2074A — A. Draw a Square | Alternative Simple Approach
Difference between en2 and en3, changed 54 character(s)
I solved **2074A — A. Draw a Square** in a slightly different way.↵
↵
### Idea↵
↵
We are given four values:↵
↵
`l, r, d, u`↵
↵
For these four points to form a square, all four distances need to be equal.↵
↵
The usual way is to check:↵
↵
```cpp↵
l == r && r == d && d == u↵
```↵
↵
But I used a different and simple way.↵
↵
First, I find the **minimum** and **maximum** among the four values.↵
↵
```cpp↵
ll mn = min({l, r, d, u});↵
ll mx = max({l, r, d, u});↵
```↵
↵
Now notice:↵
↵
* If all four values are equal, the minimum and maximum will also be equal.↵
* If the minimum and maximum are different, then at least one value is different.↵
↵
So the condition becomes:↵
↵
```text↵
mn == mx  →  YES↵
mn != mx  →  NO↵
```↵
↵
### Code↵
↵
```cpp↵
#include <bits/stdc++.h>↵
using namespace std;↵
↵
#define ll long long↵
↵
int32_t main()↵
{↵
    ios_base::sync_with_stdio(false);↵
    cin.tie(nullptr);↵
↵
    ll t;↵
    cin >> t;↵
↵
    while (t--)↵
    {↵
        ll l, r, d, u;↵
        cin >> l >> r >> d >> u;↵
↵
        ll mn = min({l, r, d, u});↵
        ll mx = max({l, r, d, u});↵
↵
        if (mn == mx)↵
           {↵
    
            cout << "YESes\n";↵
           }↵
        else{↵
            cout
 << "NOo\n";↵
        }↵
    }↵
}↵
```↵
### Example 1↵
Suppose:↵
```text↵
2 2 2 2↵
```↵
↵
Then:↵
```text↵
mn = 2↵
mx = 2↵
```↵
So `mn == mx`, therefore the answer is:↵
↵
```text↵
YES↵
```↵
### Example 2↵
↵
Suppose:↵
```text↵
1 2 1 1↵
```↵
↵
Then:↵
```text↵
mn = 1↵
mx = 2↵
```↵
↵
So `mn != mx`, therefore the answer is:↵
```text↵
NO↵
```↵
↵
### Complexity↵
For each test case:↵
* **Time:** `O(1)`↵
* **Space:** `O(1)`↵
↵
This is basically the same condition as checking all four values directly, but using the minimum and maximum gives another simple way to think about the problem.↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English OddOneOut 2026-10-04 20:35:19 54
en2 English OddOneOut 2026-10-04 19:38:56 68
en1 English OddOneOut 2026-10-04 19:34:34 1866 Added alternative min/max approach (published)