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.
Forget red for a second. The final blue cells are exactly one interval of length , because blue is painted last and nothing overwrites it.
For the whole coloring to be symmetric, that blue interval must mirror to itself. A length- interval can sit centered in cells only when is even.
Once blue is centered, red cells inside the blue segment do not matter at all. They get erased. Only red sticking out outside the blue segment can affect symmetry.
If , the whole red segment can be placed inside the blue segment. Then red disappears, and the final coloring is just one centered blue block.
If , some red must survive. Those surviving red cells must stick out equally on both sides of the centered blue block, so the red interval must also be centered. That is possible exactly when is even.
The key is to stop thinking about the two painting operations as equally important. They are not. Blue is painted second, so blue is the boss.
Let the red interval be with length , and the blue interval be with length .
After both operations:
So the final blue cells are exactly the interval .
Blue must be centered
In a symmetric coloring, if cell is blue, then cell must also be blue. Since the blue cells form one consecutive interval, that interval must reflect to itself.
A length- interval can be centered in a row of length iff the empty space outside it splits evenly between the left and right sides. That means:
If is odd, blue cannot be symmetric no matter what red does. Red cannot save you here; blue is already final paint. Brutal but fair.
So the first required condition is:
Now handle red
Assume the blue interval is centered.
There are two cases.
Case 1:
The red interval is no longer than the blue interval. We can simply place the entire red interval inside the blue interval.
Then blue paints over all red cells, so no red remains in the final coloring. The final picture is just:
That is symmetric.
So if , the red part causes zero problems.
Case 2:
Now the red interval is longer than the blue interval, so red cannot be fully hidden. Some red cells must survive outside the blue block.
Since the blue block is centered, any surviving red on the left must be matched by surviving red on the right. Because the original red cells came from one consecutive interval, this means the red interval must extend equally past both sides of the centered blue interval.
In other words: the red interval itself must also be centered.
A length- interval can be centered in cells iff:
If this holds, put both intervals centered. Since , the red interval contains the blue interval, leaving equal red overhangs on both sides. Symmetric.
If it does not hold, there is no centered red interval of length . Any off-center red interval leaves unmatched red somewhere, which breaks symmetry. No weird hack exists here; the mirror check catches it immediately.
Final condition
We need blue to be centerable, and then red must either be fully hidden or centerable too:
That is the entire problem. One parity check, one size check, done.
#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--) {
ll n, a, b;
cin >> n >> a >> b;
bool blueCanBeCentered = ((n - b) % 2 == 0);
bool redCanWork = (a <= b) || ((n - a) % 2 == 0);
cout << (blueCanBeCentered && redCanWork ? "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--) {
ll n, a, b;
cin >> n >> a >> b;
bool blueCanBeCentered = ((n - b) % 2 == 0);
bool redCanWork = (a <= b) || ((n - a) % 2 == 0);
cout << (blueCanBeCentered && redCanWork ? "YES" : "NO") << '\n';
}
return 0;
}