#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, ll l1, ll l2) {
if (c1 == 0) return false;
if (c2 == 0) return true;
if (f2 && c1 >= f2*S && c2 <= f1*S) return true;
if (c2 + f2*S <= c1) return true;
if (c1 >= c2 && f1 >= f2) 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, cnt1, cnt1);
}
else {
return !go(c2, f2-cnt2-1, c1, f1-cnt2, cnt2, cnt2+1);
}
}
if (c1 - f2*S >= S) {
if (f2*S < c1) {
if (!go(c2-(c1-f2*S), f2, c1, f1, l2, 0))
return true;
}
if (f2 && (c1 <= (f2+1)*S || l1 <= 5)) {
if (!go(c2, f2-1, c1, f1, l2, l1+1))
return true;
}
}
else {
if (f2 && (c1 <= (f2+1)*S || l1 <= 5)) {
if (!go(c2, f2-1, c1, f1, l2, l1+1))
return true;
}
if (f2*S < c1) {
if (!go(c2-(c1-f2*S), f2, c1, f1, l2, 0))
return true;
}
}
return false;
}
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, 0, 0)) {
cout << "YES\n";
}
else cout << "NO\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
431 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 |
157 ms |
1100 KB |
Output is correct |
3 |
Correct |
69 ms |
1108 KB |
Output is correct |
4 |
Correct |
46 ms |
1216 KB |
Output is correct |
5 |
Correct |
46 ms |
1104 KB |
Output is correct |
6 |
Correct |
59 ms |
1316 KB |
Output is correct |
7 |
Correct |
56 ms |
1312 KB |
Output is correct |
8 |
Correct |
62 ms |
1208 KB |
Output is correct |
9 |
Correct |
45 ms |
1320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
157 ms |
1100 KB |
Output is correct |
3 |
Correct |
69 ms |
1108 KB |
Output is correct |
4 |
Correct |
46 ms |
1216 KB |
Output is correct |
5 |
Correct |
46 ms |
1104 KB |
Output is correct |
6 |
Correct |
59 ms |
1316 KB |
Output is correct |
7 |
Correct |
56 ms |
1312 KB |
Output is correct |
8 |
Correct |
62 ms |
1208 KB |
Output is correct |
9 |
Correct |
45 ms |
1320 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
161 ms |
1188 KB |
Output is correct |
12 |
Correct |
68 ms |
1276 KB |
Output is correct |
13 |
Correct |
46 ms |
1208 KB |
Output is correct |
14 |
Correct |
56 ms |
1104 KB |
Output is correct |
15 |
Correct |
56 ms |
1112 KB |
Output is correct |
16 |
Correct |
57 ms |
1108 KB |
Output is correct |
17 |
Correct |
62 ms |
1312 KB |
Output is correct |
18 |
Correct |
40 ms |
1152 KB |
Output is correct |
19 |
Correct |
2300 ms |
1328 KB |
Output is correct |
20 |
Correct |
773 ms |
1136 KB |
Output is correct |
21 |
Correct |
105 ms |
1360 KB |
Output is correct |
22 |
Correct |
65 ms |
1100 KB |
Output is correct |
23 |
Correct |
67 ms |
1292 KB |
Output is correct |
24 |
Correct |
68 ms |
1364 KB |
Output is correct |
25 |
Correct |
74 ms |
1324 KB |
Output is correct |
26 |
Correct |
86 ms |
1364 KB |
Output is correct |
27 |
Correct |
71 ms |
1360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
437 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 |
157 ms |
1100 KB |
Output is correct |
3 |
Correct |
69 ms |
1108 KB |
Output is correct |
4 |
Correct |
46 ms |
1216 KB |
Output is correct |
5 |
Correct |
46 ms |
1104 KB |
Output is correct |
6 |
Correct |
59 ms |
1316 KB |
Output is correct |
7 |
Correct |
56 ms |
1312 KB |
Output is correct |
8 |
Correct |
62 ms |
1208 KB |
Output is correct |
9 |
Correct |
45 ms |
1320 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
161 ms |
1188 KB |
Output is correct |
12 |
Correct |
68 ms |
1276 KB |
Output is correct |
13 |
Correct |
46 ms |
1208 KB |
Output is correct |
14 |
Correct |
56 ms |
1104 KB |
Output is correct |
15 |
Correct |
56 ms |
1112 KB |
Output is correct |
16 |
Correct |
57 ms |
1108 KB |
Output is correct |
17 |
Correct |
62 ms |
1312 KB |
Output is correct |
18 |
Correct |
40 ms |
1152 KB |
Output is correct |
19 |
Correct |
2300 ms |
1328 KB |
Output is correct |
20 |
Correct |
773 ms |
1136 KB |
Output is correct |
21 |
Correct |
105 ms |
1360 KB |
Output is correct |
22 |
Correct |
65 ms |
1100 KB |
Output is correct |
23 |
Correct |
67 ms |
1292 KB |
Output is correct |
24 |
Correct |
68 ms |
1364 KB |
Output is correct |
25 |
Correct |
74 ms |
1324 KB |
Output is correct |
26 |
Correct |
86 ms |
1364 KB |
Output is correct |
27 |
Correct |
71 ms |
1360 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
158 ms |
1108 KB |
Output is correct |
30 |
Correct |
70 ms |
1108 KB |
Output is correct |
31 |
Correct |
53 ms |
1408 KB |
Output is correct |
32 |
Correct |
47 ms |
1108 KB |
Output is correct |
33 |
Correct |
54 ms |
1104 KB |
Output is correct |
34 |
Correct |
57 ms |
1096 KB |
Output is correct |
35 |
Correct |
63 ms |
1108 KB |
Output is correct |
36 |
Correct |
41 ms |
1108 KB |
Output is correct |
37 |
Correct |
2301 ms |
1360 KB |
Output is correct |
38 |
Correct |
766 ms |
1108 KB |
Output is correct |
39 |
Correct |
106 ms |
1360 KB |
Output is correct |
40 |
Correct |
66 ms |
1104 KB |
Output is correct |
41 |
Correct |
65 ms |
1104 KB |
Output is correct |
42 |
Correct |
62 ms |
1360 KB |
Output is correct |
43 |
Correct |
81 ms |
1356 KB |
Output is correct |
44 |
Correct |
95 ms |
1364 KB |
Output is correct |
45 |
Correct |
79 ms |
1360 KB |
Output is correct |
46 |
Correct |
239 ms |
1416 KB |
Output is correct |
47 |
Execution timed out |
4034 ms |
848 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
157 ms |
1100 KB |
Output is correct |
3 |
Correct |
69 ms |
1108 KB |
Output is correct |
4 |
Correct |
46 ms |
1216 KB |
Output is correct |
5 |
Correct |
46 ms |
1104 KB |
Output is correct |
6 |
Correct |
59 ms |
1316 KB |
Output is correct |
7 |
Correct |
56 ms |
1312 KB |
Output is correct |
8 |
Correct |
62 ms |
1208 KB |
Output is correct |
9 |
Correct |
45 ms |
1320 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
161 ms |
1188 KB |
Output is correct |
12 |
Correct |
68 ms |
1276 KB |
Output is correct |
13 |
Correct |
46 ms |
1208 KB |
Output is correct |
14 |
Correct |
56 ms |
1104 KB |
Output is correct |
15 |
Correct |
56 ms |
1112 KB |
Output is correct |
16 |
Correct |
57 ms |
1108 KB |
Output is correct |
17 |
Correct |
62 ms |
1312 KB |
Output is correct |
18 |
Correct |
40 ms |
1152 KB |
Output is correct |
19 |
Correct |
2300 ms |
1328 KB |
Output is correct |
20 |
Correct |
773 ms |
1136 KB |
Output is correct |
21 |
Correct |
105 ms |
1360 KB |
Output is correct |
22 |
Correct |
65 ms |
1100 KB |
Output is correct |
23 |
Correct |
67 ms |
1292 KB |
Output is correct |
24 |
Correct |
68 ms |
1364 KB |
Output is correct |
25 |
Correct |
74 ms |
1324 KB |
Output is correct |
26 |
Correct |
86 ms |
1364 KB |
Output is correct |
27 |
Correct |
71 ms |
1360 KB |
Output is correct |
28 |
Runtime error |
437 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 |
157 ms |
1100 KB |
Output is correct |
3 |
Correct |
69 ms |
1108 KB |
Output is correct |
4 |
Correct |
46 ms |
1216 KB |
Output is correct |
5 |
Correct |
46 ms |
1104 KB |
Output is correct |
6 |
Correct |
59 ms |
1316 KB |
Output is correct |
7 |
Correct |
56 ms |
1312 KB |
Output is correct |
8 |
Correct |
62 ms |
1208 KB |
Output is correct |
9 |
Correct |
45 ms |
1320 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
157 ms |
1360 KB |
Output is correct |
12 |
Correct |
68 ms |
1104 KB |
Output is correct |
13 |
Correct |
47 ms |
1108 KB |
Output is correct |
14 |
Correct |
46 ms |
1268 KB |
Output is correct |
15 |
Correct |
54 ms |
1108 KB |
Output is correct |
16 |
Correct |
59 ms |
1264 KB |
Output is correct |
17 |
Correct |
69 ms |
1260 KB |
Output is correct |
18 |
Correct |
41 ms |
1092 KB |
Output is correct |
19 |
Execution timed out |
4062 ms |
520 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 |
157 ms |
1100 KB |
Output is correct |
3 |
Correct |
69 ms |
1108 KB |
Output is correct |
4 |
Correct |
46 ms |
1216 KB |
Output is correct |
5 |
Correct |
46 ms |
1104 KB |
Output is correct |
6 |
Correct |
59 ms |
1316 KB |
Output is correct |
7 |
Correct |
56 ms |
1312 KB |
Output is correct |
8 |
Correct |
62 ms |
1208 KB |
Output is correct |
9 |
Correct |
45 ms |
1320 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
161 ms |
1188 KB |
Output is correct |
12 |
Correct |
68 ms |
1276 KB |
Output is correct |
13 |
Correct |
46 ms |
1208 KB |
Output is correct |
14 |
Correct |
56 ms |
1104 KB |
Output is correct |
15 |
Correct |
56 ms |
1112 KB |
Output is correct |
16 |
Correct |
57 ms |
1108 KB |
Output is correct |
17 |
Correct |
62 ms |
1312 KB |
Output is correct |
18 |
Correct |
40 ms |
1152 KB |
Output is correct |
19 |
Correct |
2300 ms |
1328 KB |
Output is correct |
20 |
Correct |
773 ms |
1136 KB |
Output is correct |
21 |
Correct |
105 ms |
1360 KB |
Output is correct |
22 |
Correct |
65 ms |
1100 KB |
Output is correct |
23 |
Correct |
67 ms |
1292 KB |
Output is correct |
24 |
Correct |
68 ms |
1364 KB |
Output is correct |
25 |
Correct |
74 ms |
1324 KB |
Output is correct |
26 |
Correct |
86 ms |
1364 KB |
Output is correct |
27 |
Correct |
71 ms |
1360 KB |
Output is correct |
28 |
Runtime error |
437 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |