#include <stdio.h>
#include <stdlib.h>
#define C 30000
#define R 174 /* R = ceil(sqrt(C)) */
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
int **dpmn[C + 1], **dpmx[C + 1], **dqmn[C + 1], **dqmx[C + 1];
int c;
int solve(long long x1, long long y1, long long x2, long long y2) {
long long y;
int w;
if (x1 + y1 * c <= 0)
return 0;
if (x2 + y2 * c <= 0)
return 1;
if (x1 <= 0) {
if (x2 > 0) {
if (x2 >= c)
return 0;
if (y2 > 0) {
if (x2 - x1 >= c)
return 0;
return !solve(x2, y2, x1 + c, y1 - 1);
}
y = -x1 / (c - x2) + 1;
return y <= y1 && solve(x1 + y * (c - x2), y1 - y, x2, y2);
} else {
y = min(-x1 / c + 1, -x2 / c + 1);
return solve(x1 + y * c, y1 - y, x2 + y * c, y2 - y);
}
}
if (x1 >= x2 && (x1 >= c || y1 > 0))
return 1;
if (x2 < c && x1 + y1 * (c - x2) >= c)
return 1;
if (x2 >= 0 && x2 < c) {
if (c - x1 >= 0 && c - x1 <= R) {
if (y2 < dpmn[x2][y1][c - x1])
return 1;
if (y2 > dpmx[x2][y1][c - x1])
return 0;
}
if (y2 <= R) {
if (x1 < dqmn[x2][y1][y2])
return 0;
if (x1 > dqmx[x2][y1][y2])
return 1;
}
}
if (!solve(x2 - x1, y2, x1, y1)) {
if (x2 >= 0 && x2 < c) {
if (c - x1 >= 0 && c - x1 <= R)
dpmn[x2][y1][c - x1] = max(dpmn[x2][y1][c - x1], y2 + 1);
if (y2 <= R)
dqmx[x2][y1][y2] = min(dqmx[x2][y1][y2], x1 - 1);
}
return 1;
}
if (x2 >= c)
return 0;
y = y2 == 0 ? 1 : max(min((x2 + c * (y2 - 1)) / (y2 + 1), x2) - x1, 0) / (c - x2) + 1;
w = y <= y1 && solve(x1 + y * (c - x2), y1 - y, x2, y2);
if (x2 >= 0 && x2 < c) {
if (w) {
if (c - x1 >= 0 && c - x1 <= R)
dpmn[x2][y1][c - x1] = max(dpmn[x2][y1][c - x1], y2 + 1);
if (y2 <= R)
dqmx[x2][y1][y2] = min(dqmx[x2][y1][y2], x1 - 1);
} else {
if (c - x1 >= 0 && c - x1 <= R)
dpmx[x2][y1][c - x1] = min(dpmx[x2][y1][c - x1], y2 - 1);
if (y2 <= R)
dqmn[x2][y1][y2] = max(dqmn[x2][y1][y2], x1 + 1);
}
}
return w;
}
int main() {
int t, x1, y1, x2, y2;
scanf("%d%d", &c, &t);
for (x2 = 0; x2 < c; x2++) {
dpmn[x2] = (int **) malloc((c / (c - x2) + 1) * sizeof *dpmn[x2]);
dpmx[x2] = (int **) malloc((c / (c - x2) + 1) * sizeof *dpmx[x2]);
dqmn[x2] = (int **) malloc((c / (c - x2) + 1) * sizeof *dqmn[x2]);
dqmx[x2] = (int **) malloc((c / (c - x2) + 1) * sizeof *dqmx[x2]);
for (y1 = 0; y1 * (c - x2) <= c; y1++) {
dpmn[x2][y1] = (int *) malloc((R + 1) * sizeof *dpmn[x2][y1]);
dpmx[x2][y1] = (int *) malloc((R + 1) * sizeof *dpmx[x2][y1]);
dqmn[x2][y1] = (int *) malloc((R + 1) * sizeof *dqmn[x2][y1]);
dqmx[x2][y1] = (int *) malloc((R + 1) * sizeof *dqmx[x2][y1]);
for (x1 = 0; x1 <= R; x1++)
dpmn[x2][y1][x1] = 0, dpmx[x2][y1][x1] = c;
for (y2 = 0; y2 <= R; y2++)
dqmn[x2][y1][y2] = 0, dqmx[x2][y1][y2] = c;
}
}
while (t--) {
long long x1, y1, x2, y2;
scanf("%lld%lld%lld%lld", &x1, &y2, &x2, &y1), x1 -= y1 * c, x2 -= y2 * c;
printf(solve(x1, y1, x2, y2) ? "YES\n" : "NO\n");
}
return 0;
}
Compilation message
gradingserver.c: In function 'main':
gradingserver.c:87:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | scanf("%d%d", &c, &t);
| ^~~~~~~~~~~~~~~~~~~~~
gradingserver.c:107:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | scanf("%lld%lld%lld%lld", &x1, &y2, &x2, &y1), x1 -= y1 * c, x2 -= y2 * c;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
67 ms |
4096 KB |
Output is correct |
3 |
Incorrect |
49 ms |
4176 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
67 ms |
4096 KB |
Output is correct |
3 |
Incorrect |
49 ms |
4176 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
13392 KB |
Output is correct |
2 |
Correct |
95 ms |
12476 KB |
Output is correct |
3 |
Correct |
118 ms |
12992 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
67 ms |
4096 KB |
Output is correct |
3 |
Incorrect |
49 ms |
4176 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
67 ms |
4096 KB |
Output is correct |
3 |
Incorrect |
49 ms |
4176 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
67 ms |
4096 KB |
Output is correct |
3 |
Incorrect |
49 ms |
4176 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
67 ms |
4096 KB |
Output is correct |
3 |
Incorrect |
49 ms |
4176 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |