Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
A square has four sides, and every side length must be the same.
Each stick must become exactly one side, because you cannot break or bend sticks.
The order of the sticks does not matter. You can rearrange them however you want.
Having two matching pairs is not enough: can make a rectangle, but not a square.
So the whole check is just whether . If yes, print YES; otherwise print NO.
Key idea
A square is brutally picky: all four sides must have the same length.
We are given exactly four sticks, and we cannot break or bend them. That means each stick has to be used as one full side of the square. So there is no clever construction, no hidden geometry trick, no “maybe if we rotate it” nonsense. If one stick has a different length, one side of the square would be different, and the square is dead.
So the condition is simply:
If that is true, we can place the four sticks as the four sides of a square. If not, we cannot.
Why pairs are not enough
A common wrong thought is: “If opposite sides match, that should work.” Nope. That gives you a rectangle, not necessarily a square.
For example:
These can form a rectangle with side lengths and , but a square needs all sides equal. Rectangles are square cosplay, not squares.
Algorithm
For each test case:
YES if they are, otherwise print NO.Correctness proof
We prove the algorithm prints YES exactly when a square can be formed.
If the algorithm prints YES, then . Since all four sticks have equal length, we can use them as the four equal sides of a square. Therefore, forming a square is possible.
If a square can be formed, then its four sides must all have equal length by definition. Since the four given sticks are exactly the four sides and cannot be changed, their lengths must satisfy . Therefore, the algorithm prints YES.
Thus, the algorithm is correct.
Complexity
Each test case uses only a constant number of comparisons.
Time complexity: per test case, or total.
Memory complexity: .
Tiny problem, tiny solution. The geometry got folded into one equality check.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << (a == b && b == c && c == d ? "YES" : "NO") << '\n';
}
return 0;
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << (a == b && b == c && c == d ? "YES" : "NO") << '\n';
}
return 0;
}