#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 == 0)) {
if (!go(c2, f2-1, c1, f1, l2, l1+1))
return true;
}
}
else {
if (f2 && (c1 <= (f2+1)*S || l1 == 0)) {
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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
469 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 |
158 ms |
1160 KB |
Output is correct |
3 |
Correct |
80 ms |
1264 KB |
Output is correct |
4 |
Correct |
57 ms |
1244 KB |
Output is correct |
5 |
Correct |
49 ms |
1112 KB |
Output is correct |
6 |
Correct |
58 ms |
1248 KB |
Output is correct |
7 |
Correct |
58 ms |
1168 KB |
Output is correct |
8 |
Correct |
75 ms |
1240 KB |
Output is correct |
9 |
Correct |
43 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
158 ms |
1160 KB |
Output is correct |
3 |
Correct |
80 ms |
1264 KB |
Output is correct |
4 |
Correct |
57 ms |
1244 KB |
Output is correct |
5 |
Correct |
49 ms |
1112 KB |
Output is correct |
6 |
Correct |
58 ms |
1248 KB |
Output is correct |
7 |
Correct |
58 ms |
1168 KB |
Output is correct |
8 |
Correct |
75 ms |
1240 KB |
Output is correct |
9 |
Correct |
43 ms |
1144 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
171 ms |
1156 KB |
Output is correct |
12 |
Correct |
73 ms |
1072 KB |
Output is correct |
13 |
Correct |
57 ms |
1292 KB |
Output is correct |
14 |
Correct |
53 ms |
1104 KB |
Output is correct |
15 |
Correct |
65 ms |
1088 KB |
Output is correct |
16 |
Correct |
59 ms |
1260 KB |
Output is correct |
17 |
Correct |
62 ms |
1112 KB |
Output is correct |
18 |
Correct |
66 ms |
1112 KB |
Output is correct |
19 |
Correct |
2815 ms |
1332 KB |
Output is correct |
20 |
Correct |
995 ms |
1320 KB |
Output is correct |
21 |
Correct |
150 ms |
1140 KB |
Output is correct |
22 |
Correct |
71 ms |
1244 KB |
Output is correct |
23 |
Correct |
78 ms |
1292 KB |
Output is correct |
24 |
Correct |
96 ms |
1188 KB |
Output is correct |
25 |
Correct |
107 ms |
1256 KB |
Output is correct |
26 |
Correct |
88 ms |
1284 KB |
Output is correct |
27 |
Correct |
73 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
481 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 |
158 ms |
1160 KB |
Output is correct |
3 |
Correct |
80 ms |
1264 KB |
Output is correct |
4 |
Correct |
57 ms |
1244 KB |
Output is correct |
5 |
Correct |
49 ms |
1112 KB |
Output is correct |
6 |
Correct |
58 ms |
1248 KB |
Output is correct |
7 |
Correct |
58 ms |
1168 KB |
Output is correct |
8 |
Correct |
75 ms |
1240 KB |
Output is correct |
9 |
Correct |
43 ms |
1144 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
171 ms |
1156 KB |
Output is correct |
12 |
Correct |
73 ms |
1072 KB |
Output is correct |
13 |
Correct |
57 ms |
1292 KB |
Output is correct |
14 |
Correct |
53 ms |
1104 KB |
Output is correct |
15 |
Correct |
65 ms |
1088 KB |
Output is correct |
16 |
Correct |
59 ms |
1260 KB |
Output is correct |
17 |
Correct |
62 ms |
1112 KB |
Output is correct |
18 |
Correct |
66 ms |
1112 KB |
Output is correct |
19 |
Correct |
2815 ms |
1332 KB |
Output is correct |
20 |
Correct |
995 ms |
1320 KB |
Output is correct |
21 |
Correct |
150 ms |
1140 KB |
Output is correct |
22 |
Correct |
71 ms |
1244 KB |
Output is correct |
23 |
Correct |
78 ms |
1292 KB |
Output is correct |
24 |
Correct |
96 ms |
1188 KB |
Output is correct |
25 |
Correct |
107 ms |
1256 KB |
Output is correct |
26 |
Correct |
88 ms |
1284 KB |
Output is correct |
27 |
Correct |
73 ms |
1228 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
167 ms |
1132 KB |
Output is correct |
30 |
Correct |
77 ms |
1108 KB |
Output is correct |
31 |
Correct |
76 ms |
1104 KB |
Output is correct |
32 |
Correct |
79 ms |
1104 KB |
Output is correct |
33 |
Correct |
53 ms |
1284 KB |
Output is correct |
34 |
Correct |
56 ms |
1108 KB |
Output is correct |
35 |
Correct |
93 ms |
1076 KB |
Output is correct |
36 |
Correct |
44 ms |
1108 KB |
Output is correct |
37 |
Correct |
2634 ms |
1252 KB |
Output is correct |
38 |
Correct |
862 ms |
1124 KB |
Output is correct |
39 |
Correct |
121 ms |
1364 KB |
Output is correct |
40 |
Correct |
97 ms |
1352 KB |
Output is correct |
41 |
Correct |
66 ms |
1156 KB |
Output is correct |
42 |
Correct |
64 ms |
1360 KB |
Output is correct |
43 |
Correct |
81 ms |
1368 KB |
Output is correct |
44 |
Correct |
134 ms |
1360 KB |
Output is correct |
45 |
Correct |
87 ms |
1376 KB |
Output is correct |
46 |
Correct |
258 ms |
1444 KB |
Output is correct |
47 |
Execution timed out |
4075 ms |
648 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 |
158 ms |
1160 KB |
Output is correct |
3 |
Correct |
80 ms |
1264 KB |
Output is correct |
4 |
Correct |
57 ms |
1244 KB |
Output is correct |
5 |
Correct |
49 ms |
1112 KB |
Output is correct |
6 |
Correct |
58 ms |
1248 KB |
Output is correct |
7 |
Correct |
58 ms |
1168 KB |
Output is correct |
8 |
Correct |
75 ms |
1240 KB |
Output is correct |
9 |
Correct |
43 ms |
1144 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
171 ms |
1156 KB |
Output is correct |
12 |
Correct |
73 ms |
1072 KB |
Output is correct |
13 |
Correct |
57 ms |
1292 KB |
Output is correct |
14 |
Correct |
53 ms |
1104 KB |
Output is correct |
15 |
Correct |
65 ms |
1088 KB |
Output is correct |
16 |
Correct |
59 ms |
1260 KB |
Output is correct |
17 |
Correct |
62 ms |
1112 KB |
Output is correct |
18 |
Correct |
66 ms |
1112 KB |
Output is correct |
19 |
Correct |
2815 ms |
1332 KB |
Output is correct |
20 |
Correct |
995 ms |
1320 KB |
Output is correct |
21 |
Correct |
150 ms |
1140 KB |
Output is correct |
22 |
Correct |
71 ms |
1244 KB |
Output is correct |
23 |
Correct |
78 ms |
1292 KB |
Output is correct |
24 |
Correct |
96 ms |
1188 KB |
Output is correct |
25 |
Correct |
107 ms |
1256 KB |
Output is correct |
26 |
Correct |
88 ms |
1284 KB |
Output is correct |
27 |
Correct |
73 ms |
1228 KB |
Output is correct |
28 |
Runtime error |
481 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 |
158 ms |
1160 KB |
Output is correct |
3 |
Correct |
80 ms |
1264 KB |
Output is correct |
4 |
Correct |
57 ms |
1244 KB |
Output is correct |
5 |
Correct |
49 ms |
1112 KB |
Output is correct |
6 |
Correct |
58 ms |
1248 KB |
Output is correct |
7 |
Correct |
58 ms |
1168 KB |
Output is correct |
8 |
Correct |
75 ms |
1240 KB |
Output is correct |
9 |
Correct |
43 ms |
1144 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
186 ms |
1116 KB |
Output is correct |
12 |
Correct |
81 ms |
1104 KB |
Output is correct |
13 |
Correct |
47 ms |
1196 KB |
Output is correct |
14 |
Correct |
47 ms |
1104 KB |
Output is correct |
15 |
Correct |
59 ms |
1164 KB |
Output is correct |
16 |
Correct |
60 ms |
1104 KB |
Output is correct |
17 |
Correct |
72 ms |
1228 KB |
Output is correct |
18 |
Correct |
76 ms |
1176 KB |
Output is correct |
19 |
Execution timed out |
4024 ms |
592 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 |
158 ms |
1160 KB |
Output is correct |
3 |
Correct |
80 ms |
1264 KB |
Output is correct |
4 |
Correct |
57 ms |
1244 KB |
Output is correct |
5 |
Correct |
49 ms |
1112 KB |
Output is correct |
6 |
Correct |
58 ms |
1248 KB |
Output is correct |
7 |
Correct |
58 ms |
1168 KB |
Output is correct |
8 |
Correct |
75 ms |
1240 KB |
Output is correct |
9 |
Correct |
43 ms |
1144 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
171 ms |
1156 KB |
Output is correct |
12 |
Correct |
73 ms |
1072 KB |
Output is correct |
13 |
Correct |
57 ms |
1292 KB |
Output is correct |
14 |
Correct |
53 ms |
1104 KB |
Output is correct |
15 |
Correct |
65 ms |
1088 KB |
Output is correct |
16 |
Correct |
59 ms |
1260 KB |
Output is correct |
17 |
Correct |
62 ms |
1112 KB |
Output is correct |
18 |
Correct |
66 ms |
1112 KB |
Output is correct |
19 |
Correct |
2815 ms |
1332 KB |
Output is correct |
20 |
Correct |
995 ms |
1320 KB |
Output is correct |
21 |
Correct |
150 ms |
1140 KB |
Output is correct |
22 |
Correct |
71 ms |
1244 KB |
Output is correct |
23 |
Correct |
78 ms |
1292 KB |
Output is correct |
24 |
Correct |
96 ms |
1188 KB |
Output is correct |
25 |
Correct |
107 ms |
1256 KB |
Output is correct |
26 |
Correct |
88 ms |
1284 KB |
Output is correct |
27 |
Correct |
73 ms |
1228 KB |
Output is correct |
28 |
Runtime error |
481 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |