#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 (c1 - f2*S >= S) {
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;
}
}
else {
if (f2) {
if (!go(c2, f2-1, c1, f1))
return dp[{c1,f1,c2,f2}] = 1;
}
if (f2*S < c1) {
if (!go(c2-(c1-f2*S), f2, 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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
432 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
190 ms |
16884 KB |
Output is correct |
3 |
Correct |
116 ms |
7064 KB |
Output is correct |
4 |
Correct |
135 ms |
9812 KB |
Output is correct |
5 |
Correct |
258 ms |
19540 KB |
Output is correct |
6 |
Correct |
140 ms |
5972 KB |
Output is correct |
7 |
Correct |
144 ms |
6484 KB |
Output is correct |
8 |
Correct |
159 ms |
8528 KB |
Output is correct |
9 |
Correct |
105 ms |
9296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
190 ms |
16884 KB |
Output is correct |
3 |
Correct |
116 ms |
7064 KB |
Output is correct |
4 |
Correct |
135 ms |
9812 KB |
Output is correct |
5 |
Correct |
258 ms |
19540 KB |
Output is correct |
6 |
Correct |
140 ms |
5972 KB |
Output is correct |
7 |
Correct |
144 ms |
6484 KB |
Output is correct |
8 |
Correct |
159 ms |
8528 KB |
Output is correct |
9 |
Correct |
105 ms |
9296 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
197 ms |
16880 KB |
Output is correct |
12 |
Correct |
109 ms |
6924 KB |
Output is correct |
13 |
Correct |
144 ms |
9812 KB |
Output is correct |
14 |
Correct |
270 ms |
19624 KB |
Output is correct |
15 |
Correct |
141 ms |
5976 KB |
Output is correct |
16 |
Correct |
139 ms |
6224 KB |
Output is correct |
17 |
Correct |
154 ms |
8528 KB |
Output is correct |
18 |
Correct |
109 ms |
9296 KB |
Output is correct |
19 |
Correct |
607 ms |
53332 KB |
Output is correct |
20 |
Correct |
515 ms |
47172 KB |
Output is correct |
21 |
Correct |
403 ms |
33508 KB |
Output is correct |
22 |
Correct |
815 ms |
71572 KB |
Output is correct |
23 |
Correct |
906 ms |
77300 KB |
Output is correct |
24 |
Correct |
524 ms |
51280 KB |
Output is correct |
25 |
Correct |
535 ms |
52308 KB |
Output is correct |
26 |
Correct |
557 ms |
55256 KB |
Output is correct |
27 |
Correct |
614 ms |
59112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
454 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
190 ms |
16884 KB |
Output is correct |
3 |
Correct |
116 ms |
7064 KB |
Output is correct |
4 |
Correct |
135 ms |
9812 KB |
Output is correct |
5 |
Correct |
258 ms |
19540 KB |
Output is correct |
6 |
Correct |
140 ms |
5972 KB |
Output is correct |
7 |
Correct |
144 ms |
6484 KB |
Output is correct |
8 |
Correct |
159 ms |
8528 KB |
Output is correct |
9 |
Correct |
105 ms |
9296 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
197 ms |
16880 KB |
Output is correct |
12 |
Correct |
109 ms |
6924 KB |
Output is correct |
13 |
Correct |
144 ms |
9812 KB |
Output is correct |
14 |
Correct |
270 ms |
19624 KB |
Output is correct |
15 |
Correct |
141 ms |
5976 KB |
Output is correct |
16 |
Correct |
139 ms |
6224 KB |
Output is correct |
17 |
Correct |
154 ms |
8528 KB |
Output is correct |
18 |
Correct |
109 ms |
9296 KB |
Output is correct |
19 |
Correct |
607 ms |
53332 KB |
Output is correct |
20 |
Correct |
515 ms |
47172 KB |
Output is correct |
21 |
Correct |
403 ms |
33508 KB |
Output is correct |
22 |
Correct |
815 ms |
71572 KB |
Output is correct |
23 |
Correct |
906 ms |
77300 KB |
Output is correct |
24 |
Correct |
524 ms |
51280 KB |
Output is correct |
25 |
Correct |
535 ms |
52308 KB |
Output is correct |
26 |
Correct |
557 ms |
55256 KB |
Output is correct |
27 |
Correct |
614 ms |
59112 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
187 ms |
16756 KB |
Output is correct |
30 |
Correct |
107 ms |
6996 KB |
Output is correct |
31 |
Correct |
136 ms |
9660 KB |
Output is correct |
32 |
Correct |
280 ms |
19648 KB |
Output is correct |
33 |
Correct |
153 ms |
5900 KB |
Output is correct |
34 |
Correct |
142 ms |
6224 KB |
Output is correct |
35 |
Correct |
160 ms |
8524 KB |
Output is correct |
36 |
Correct |
112 ms |
9384 KB |
Output is correct |
37 |
Correct |
629 ms |
53632 KB |
Output is correct |
38 |
Correct |
527 ms |
47188 KB |
Output is correct |
39 |
Correct |
433 ms |
33420 KB |
Output is correct |
40 |
Correct |
873 ms |
71488 KB |
Output is correct |
41 |
Correct |
1083 ms |
77356 KB |
Output is correct |
42 |
Correct |
577 ms |
51036 KB |
Output is correct |
43 |
Correct |
566 ms |
52268 KB |
Output is correct |
44 |
Correct |
586 ms |
55336 KB |
Output is correct |
45 |
Correct |
715 ms |
59216 KB |
Output is correct |
46 |
Correct |
3392 ms |
286260 KB |
Output is correct |
47 |
Execution timed out |
4094 ms |
635276 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
190 ms |
16884 KB |
Output is correct |
3 |
Correct |
116 ms |
7064 KB |
Output is correct |
4 |
Correct |
135 ms |
9812 KB |
Output is correct |
5 |
Correct |
258 ms |
19540 KB |
Output is correct |
6 |
Correct |
140 ms |
5972 KB |
Output is correct |
7 |
Correct |
144 ms |
6484 KB |
Output is correct |
8 |
Correct |
159 ms |
8528 KB |
Output is correct |
9 |
Correct |
105 ms |
9296 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
197 ms |
16880 KB |
Output is correct |
12 |
Correct |
109 ms |
6924 KB |
Output is correct |
13 |
Correct |
144 ms |
9812 KB |
Output is correct |
14 |
Correct |
270 ms |
19624 KB |
Output is correct |
15 |
Correct |
141 ms |
5976 KB |
Output is correct |
16 |
Correct |
139 ms |
6224 KB |
Output is correct |
17 |
Correct |
154 ms |
8528 KB |
Output is correct |
18 |
Correct |
109 ms |
9296 KB |
Output is correct |
19 |
Correct |
607 ms |
53332 KB |
Output is correct |
20 |
Correct |
515 ms |
47172 KB |
Output is correct |
21 |
Correct |
403 ms |
33508 KB |
Output is correct |
22 |
Correct |
815 ms |
71572 KB |
Output is correct |
23 |
Correct |
906 ms |
77300 KB |
Output is correct |
24 |
Correct |
524 ms |
51280 KB |
Output is correct |
25 |
Correct |
535 ms |
52308 KB |
Output is correct |
26 |
Correct |
557 ms |
55256 KB |
Output is correct |
27 |
Correct |
614 ms |
59112 KB |
Output is correct |
28 |
Runtime error |
454 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
190 ms |
16884 KB |
Output is correct |
3 |
Correct |
116 ms |
7064 KB |
Output is correct |
4 |
Correct |
135 ms |
9812 KB |
Output is correct |
5 |
Correct |
258 ms |
19540 KB |
Output is correct |
6 |
Correct |
140 ms |
5972 KB |
Output is correct |
7 |
Correct |
144 ms |
6484 KB |
Output is correct |
8 |
Correct |
159 ms |
8528 KB |
Output is correct |
9 |
Correct |
105 ms |
9296 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
190 ms |
16832 KB |
Output is correct |
12 |
Correct |
107 ms |
6992 KB |
Output is correct |
13 |
Correct |
136 ms |
9808 KB |
Output is correct |
14 |
Correct |
257 ms |
19632 KB |
Output is correct |
15 |
Correct |
140 ms |
5968 KB |
Output is correct |
16 |
Correct |
136 ms |
6220 KB |
Output is correct |
17 |
Correct |
155 ms |
8528 KB |
Output is correct |
18 |
Correct |
109 ms |
9472 KB |
Output is correct |
19 |
Execution timed out |
4082 ms |
545796 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
190 ms |
16884 KB |
Output is correct |
3 |
Correct |
116 ms |
7064 KB |
Output is correct |
4 |
Correct |
135 ms |
9812 KB |
Output is correct |
5 |
Correct |
258 ms |
19540 KB |
Output is correct |
6 |
Correct |
140 ms |
5972 KB |
Output is correct |
7 |
Correct |
144 ms |
6484 KB |
Output is correct |
8 |
Correct |
159 ms |
8528 KB |
Output is correct |
9 |
Correct |
105 ms |
9296 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
197 ms |
16880 KB |
Output is correct |
12 |
Correct |
109 ms |
6924 KB |
Output is correct |
13 |
Correct |
144 ms |
9812 KB |
Output is correct |
14 |
Correct |
270 ms |
19624 KB |
Output is correct |
15 |
Correct |
141 ms |
5976 KB |
Output is correct |
16 |
Correct |
139 ms |
6224 KB |
Output is correct |
17 |
Correct |
154 ms |
8528 KB |
Output is correct |
18 |
Correct |
109 ms |
9296 KB |
Output is correct |
19 |
Correct |
607 ms |
53332 KB |
Output is correct |
20 |
Correct |
515 ms |
47172 KB |
Output is correct |
21 |
Correct |
403 ms |
33508 KB |
Output is correct |
22 |
Correct |
815 ms |
71572 KB |
Output is correct |
23 |
Correct |
906 ms |
77300 KB |
Output is correct |
24 |
Correct |
524 ms |
51280 KB |
Output is correct |
25 |
Correct |
535 ms |
52308 KB |
Output is correct |
26 |
Correct |
557 ms |
55256 KB |
Output is correct |
27 |
Correct |
614 ms |
59112 KB |
Output is correct |
28 |
Runtime error |
454 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |