#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll S, Q;
map<array<ll,4>,bool> dp;
bool go(ll c1, ll f1, ll c2, ll f2) {
if (c1 == 0) return false;
if (c2 == 0) return true;
if (f2 && c1 >= f2*S && c2 <= f1*S) return true;
if (dp.find({c1,f1,c2,f2}) != dp.end()) return dp[{c1,f1,c2,f2}];
if (c2 + f2*S <= c1) return true;
if (c1 < f2*S && c2 < f1*S) {
ll cnt1 = f2 - c1/S;
ll cnt2 = f1 - c2/S;
if (cnt1 <= cnt2) {
return go(c1, f1-cnt1, c2, f2-cnt1);
}
else {
return !go(c2, f2-cnt2-1, c1, f1-cnt2);
}
}
if (f2*S < c1) {
if (!go(c2-(c1-f2*S), f2, c1, f1))
return dp[{c1,f1,c2,f2}] = 1;
}
if (f2) {
if (!go(c2, f2-1, c1, f1))
return dp[{c1,f1,c2,f2}] = 1;
}
return dp[{c1,f1,c2,f2}] = 0;
}
int main() {
ios_base :: sync_with_stdio(false); cin.tie(NULL);
cin >> S >> Q;
for (ll i=0; i<Q; i++) {
ll c1, f1, c2, f2;
cin >> c1 >> f1 >> c2 >> f2;
if (go(c1, f1, c2, f2)) {
cout << "YES\n";
}
else cout << "NO\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
435 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
187 ms |
16736 KB |
Output is correct |
3 |
Correct |
106 ms |
6664 KB |
Output is correct |
4 |
Correct |
132 ms |
9564 KB |
Output is correct |
5 |
Correct |
260 ms |
19464 KB |
Output is correct |
6 |
Correct |
136 ms |
5972 KB |
Output is correct |
7 |
Correct |
150 ms |
6404 KB |
Output is correct |
8 |
Correct |
164 ms |
8708 KB |
Output is correct |
9 |
Correct |
111 ms |
9040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
187 ms |
16736 KB |
Output is correct |
3 |
Correct |
106 ms |
6664 KB |
Output is correct |
4 |
Correct |
132 ms |
9564 KB |
Output is correct |
5 |
Correct |
260 ms |
19464 KB |
Output is correct |
6 |
Correct |
136 ms |
5972 KB |
Output is correct |
7 |
Correct |
150 ms |
6404 KB |
Output is correct |
8 |
Correct |
164 ms |
8708 KB |
Output is correct |
9 |
Correct |
111 ms |
9040 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
194 ms |
16880 KB |
Output is correct |
12 |
Correct |
116 ms |
6704 KB |
Output is correct |
13 |
Correct |
134 ms |
9708 KB |
Output is correct |
14 |
Correct |
264 ms |
19536 KB |
Output is correct |
15 |
Correct |
137 ms |
5976 KB |
Output is correct |
16 |
Correct |
139 ms |
6224 KB |
Output is correct |
17 |
Correct |
155 ms |
8788 KB |
Output is correct |
18 |
Correct |
110 ms |
9040 KB |
Output is correct |
19 |
Correct |
548 ms |
53904 KB |
Output is correct |
20 |
Correct |
497 ms |
47172 KB |
Output is correct |
21 |
Correct |
401 ms |
37204 KB |
Output is correct |
22 |
Correct |
805 ms |
75092 KB |
Output is correct |
23 |
Correct |
839 ms |
80976 KB |
Output is correct |
24 |
Correct |
543 ms |
55384 KB |
Output is correct |
25 |
Correct |
559 ms |
56092 KB |
Output is correct |
26 |
Correct |
468 ms |
52564 KB |
Output is correct |
27 |
Correct |
504 ms |
55616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
458 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
187 ms |
16736 KB |
Output is correct |
3 |
Correct |
106 ms |
6664 KB |
Output is correct |
4 |
Correct |
132 ms |
9564 KB |
Output is correct |
5 |
Correct |
260 ms |
19464 KB |
Output is correct |
6 |
Correct |
136 ms |
5972 KB |
Output is correct |
7 |
Correct |
150 ms |
6404 KB |
Output is correct |
8 |
Correct |
164 ms |
8708 KB |
Output is correct |
9 |
Correct |
111 ms |
9040 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
194 ms |
16880 KB |
Output is correct |
12 |
Correct |
116 ms |
6704 KB |
Output is correct |
13 |
Correct |
134 ms |
9708 KB |
Output is correct |
14 |
Correct |
264 ms |
19536 KB |
Output is correct |
15 |
Correct |
137 ms |
5976 KB |
Output is correct |
16 |
Correct |
139 ms |
6224 KB |
Output is correct |
17 |
Correct |
155 ms |
8788 KB |
Output is correct |
18 |
Correct |
110 ms |
9040 KB |
Output is correct |
19 |
Correct |
548 ms |
53904 KB |
Output is correct |
20 |
Correct |
497 ms |
47172 KB |
Output is correct |
21 |
Correct |
401 ms |
37204 KB |
Output is correct |
22 |
Correct |
805 ms |
75092 KB |
Output is correct |
23 |
Correct |
839 ms |
80976 KB |
Output is correct |
24 |
Correct |
543 ms |
55384 KB |
Output is correct |
25 |
Correct |
559 ms |
56092 KB |
Output is correct |
26 |
Correct |
468 ms |
52564 KB |
Output is correct |
27 |
Correct |
504 ms |
55616 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
191 ms |
16736 KB |
Output is correct |
30 |
Correct |
108 ms |
6624 KB |
Output is correct |
31 |
Correct |
144 ms |
9556 KB |
Output is correct |
32 |
Correct |
267 ms |
19588 KB |
Output is correct |
33 |
Correct |
138 ms |
5972 KB |
Output is correct |
34 |
Correct |
163 ms |
6228 KB |
Output is correct |
35 |
Correct |
156 ms |
8784 KB |
Output is correct |
36 |
Correct |
108 ms |
9044 KB |
Output is correct |
37 |
Correct |
583 ms |
50556 KB |
Output is correct |
38 |
Correct |
491 ms |
43864 KB |
Output is correct |
39 |
Correct |
419 ms |
33620 KB |
Output is correct |
40 |
Correct |
810 ms |
71540 KB |
Output is correct |
41 |
Correct |
863 ms |
77396 KB |
Output is correct |
42 |
Correct |
544 ms |
52048 KB |
Output is correct |
43 |
Correct |
569 ms |
52560 KB |
Output is correct |
44 |
Correct |
466 ms |
49028 KB |
Output is correct |
45 |
Correct |
520 ms |
52308 KB |
Output is correct |
46 |
Execution timed out |
4075 ms |
304536 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
187 ms |
16736 KB |
Output is correct |
3 |
Correct |
106 ms |
6664 KB |
Output is correct |
4 |
Correct |
132 ms |
9564 KB |
Output is correct |
5 |
Correct |
260 ms |
19464 KB |
Output is correct |
6 |
Correct |
136 ms |
5972 KB |
Output is correct |
7 |
Correct |
150 ms |
6404 KB |
Output is correct |
8 |
Correct |
164 ms |
8708 KB |
Output is correct |
9 |
Correct |
111 ms |
9040 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
194 ms |
16880 KB |
Output is correct |
12 |
Correct |
116 ms |
6704 KB |
Output is correct |
13 |
Correct |
134 ms |
9708 KB |
Output is correct |
14 |
Correct |
264 ms |
19536 KB |
Output is correct |
15 |
Correct |
137 ms |
5976 KB |
Output is correct |
16 |
Correct |
139 ms |
6224 KB |
Output is correct |
17 |
Correct |
155 ms |
8788 KB |
Output is correct |
18 |
Correct |
110 ms |
9040 KB |
Output is correct |
19 |
Correct |
548 ms |
53904 KB |
Output is correct |
20 |
Correct |
497 ms |
47172 KB |
Output is correct |
21 |
Correct |
401 ms |
37204 KB |
Output is correct |
22 |
Correct |
805 ms |
75092 KB |
Output is correct |
23 |
Correct |
839 ms |
80976 KB |
Output is correct |
24 |
Correct |
543 ms |
55384 KB |
Output is correct |
25 |
Correct |
559 ms |
56092 KB |
Output is correct |
26 |
Correct |
468 ms |
52564 KB |
Output is correct |
27 |
Correct |
504 ms |
55616 KB |
Output is correct |
28 |
Runtime error |
458 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
187 ms |
16736 KB |
Output is correct |
3 |
Correct |
106 ms |
6664 KB |
Output is correct |
4 |
Correct |
132 ms |
9564 KB |
Output is correct |
5 |
Correct |
260 ms |
19464 KB |
Output is correct |
6 |
Correct |
136 ms |
5972 KB |
Output is correct |
7 |
Correct |
150 ms |
6404 KB |
Output is correct |
8 |
Correct |
164 ms |
8708 KB |
Output is correct |
9 |
Correct |
111 ms |
9040 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
192 ms |
16712 KB |
Output is correct |
12 |
Correct |
113 ms |
6740 KB |
Output is correct |
13 |
Correct |
136 ms |
9556 KB |
Output is correct |
14 |
Correct |
266 ms |
19536 KB |
Output is correct |
15 |
Correct |
151 ms |
5884 KB |
Output is correct |
16 |
Correct |
152 ms |
6224 KB |
Output is correct |
17 |
Correct |
164 ms |
8788 KB |
Output is correct |
18 |
Correct |
110 ms |
9296 KB |
Output is correct |
19 |
Execution timed out |
4094 ms |
396804 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
187 ms |
16736 KB |
Output is correct |
3 |
Correct |
106 ms |
6664 KB |
Output is correct |
4 |
Correct |
132 ms |
9564 KB |
Output is correct |
5 |
Correct |
260 ms |
19464 KB |
Output is correct |
6 |
Correct |
136 ms |
5972 KB |
Output is correct |
7 |
Correct |
150 ms |
6404 KB |
Output is correct |
8 |
Correct |
164 ms |
8708 KB |
Output is correct |
9 |
Correct |
111 ms |
9040 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
194 ms |
16880 KB |
Output is correct |
12 |
Correct |
116 ms |
6704 KB |
Output is correct |
13 |
Correct |
134 ms |
9708 KB |
Output is correct |
14 |
Correct |
264 ms |
19536 KB |
Output is correct |
15 |
Correct |
137 ms |
5976 KB |
Output is correct |
16 |
Correct |
139 ms |
6224 KB |
Output is correct |
17 |
Correct |
155 ms |
8788 KB |
Output is correct |
18 |
Correct |
110 ms |
9040 KB |
Output is correct |
19 |
Correct |
548 ms |
53904 KB |
Output is correct |
20 |
Correct |
497 ms |
47172 KB |
Output is correct |
21 |
Correct |
401 ms |
37204 KB |
Output is correct |
22 |
Correct |
805 ms |
75092 KB |
Output is correct |
23 |
Correct |
839 ms |
80976 KB |
Output is correct |
24 |
Correct |
543 ms |
55384 KB |
Output is correct |
25 |
Correct |
559 ms |
56092 KB |
Output is correct |
26 |
Correct |
468 ms |
52564 KB |
Output is correct |
27 |
Correct |
504 ms |
55616 KB |
Output is correct |
28 |
Runtime error |
458 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |