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.
Try ignoring the exact values for a second and look at parity. What kinds of coordinates can long steps produce starting from ?
A long step adds to exactly one coordinate, so it never changes that coordinate’s parity. Starting from , after any number of long steps you are always at some point of the form .
Now think about the single short step. It adds to one coordinate, and you can use it at most once. So how many coordinates can change parity during the whole trip?
That means the only parity patterns you can end with are:
What parity pattern is impossible?
The only impossible case is when both and are odd. If at least one of them is even, just use long steps to build the even parts, and if needed spend your one short step on the odd coordinate. So the answer is NO iff
Long steps are boring in the best possible way: they add exactly to one coordinate.
So from , after any number of long steps, Yousef can reach any point of the form
for nonnegative integers .
In other words, with only long steps, both coordinates must stay even. Parity does not budge. Zero drama.
A short step adds to exactly one coordinate, and Yousef may use it at most once.
That means during the whole journey, he can flip the parity of at most one coordinate.
So the final reachable parity patterns are exactly:
The one pattern that cannot happen is
because that would require flipping both coordinates’ parity, and he only gets one short step. Life is cruel.
Yousef can reach iff not both and are odd.
So the condition is simply:
Equivalently:
NOYESIf both are even, just use long steps only.
If exactly one is odd, say is odd and is even, then:
Same idea if is the odd one.
So the parity condition is not just necessary — it’s also sufficient.
Each test case is answered in constant time:
For test cases, total complexity is:
with
extra memory.
Nice little implementation/math problem. Blink and you’ll overcomplicate it.
#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 x, y;
cin >> x >> y;
// Reachable unless both coordinates are odd.
cout << ((x % 2 == 1 && y % 2 == 1) ? "NO" : "YES") << '\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 x, y;
cin >> x >> y;
// Reachable unless both coordinates are odd.
cout << ((x % 2 == 1 && y % 2 == 1) ? "NO" : "YES") << '\n';
}
return 0;
}