#include <bits/stdc++.h>
using namespace std;
int main() {
int S, Q; cin >> S >> Q;
map<array<int, 4>, bool> dp;
for (int i = 0; i < Q; i++) {
array<int, 4> s;
cin >> s[0] >> s[1] >> s[2] >> s[3];
/*auto usehack = [&](){
if (ch > fg*S) cg -= ch-fg*S;
else fg--;
};
auto useserv = [&]() {
if (cg > fh*S) ch -= cg-fh*S;
else fh--;
};*/
function<void(array<int, 4>)> calc = [&](array<int, 4> in) {
if (dp.count(in)) return;
dp.insert({in, 1});
if (in[0] <= 0) {dp[in] = 0; return;}
if (in[0] > in[3]*S) {
array<int, 4> a = {in[0], in[1], in[2]-in[0]+in[3]*S, in[3]};
if (a[2] <= 0) return;
a[1]--;
calc(a);
if (dp[a] == 0) dp[in] = 0;
a[1]++;
if (a[2] > a[1]*S) {
a[0] -= a[2]-a[1]*S;
calc(a);
if (dp[a] == 0) dp[in] = 0;
}
}
array<int, 4> b = {in[0], in[1], in[2], in[3]-1};
b[1]--;
calc(b);
if (dp[b] == 0) dp[in] = 0;
b[1]++;
if (b[2] > b[1]*S) {
b[0] -= b[2]-b[1]*S;
calc(b);
if (dp[b]) dp[in] = 0;
}
};
calc(s);
cout << (dp[s] ? "YES" : "NO") << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |