Submission #1049496

# Submission time Handle Problem Language Result Execution time Memory
1049496 2024-08-08T19:38:49 Z rainboy Bring Down the Grading Server (CEOI23_gradingserver) C
65 / 100
4000 ms 166992 KB
#include <stdio.h>
#include <stdlib.h>
 
#define M	2000000
#define MD	0x7fffffff
#define X	123456789

long long min(long long a, long long b) { return a < b ? a : b; }
 
long long *ek[M]; int *ev[M], eo[M];
 
void init() {
	int h;

	for (h = 0; h < M; h++) {
		ek[h] = (long long *) malloc(2 * sizeof *ek[h]);
		ev[h] = (int *) malloc(2 * sizeof *ev[h]);
	}
}

int hash(long long k) {
	int k1 = k / MD, k2 = k % MD;

	return ((long long) k1 * X + k2) % MD * X % MD % M;
}

void put(long long k, int v) {
	int h = hash(k), o = eo[h]++;

	if (o >= 2 && (o & o - 1) == 0) {
		ek[h] = (long long *) realloc(ek[h], o * 2 * sizeof *ek[h]);
		ev[h] = (int *) realloc(ev[h], o * 2 * sizeof *ev[h]);
	}
	ek[h][o] = k, ev[h][o] = v;
}

int get(long long k) {
	int h = hash(k), o;

	for (o = eo[h]; o--; )
		if (ek[h][o] == k)
			return ev[h][o];
	return -1;
}

int c, cnt;

int solve(long long x1, long long y1, long long x2, long long y2) {
	long long y, z;
	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)
		return !solve(x2 - x1, y2, x1, y1);
	if (x1 + y1 * (c - x2) >= c)
		return 1;
	z = x1 >= 0 && x1 <= c && y1 >= 0 && y1 <= c && x2 >= 0 && x2 <= c && y2 >= 0 && y2 <= c ? (((long long) x1 * (c + 1) + y1) * (c + 1) + x2) * (c + 1) + y2 : -1;
	if (z != -1 && (w = get(z)) != -1)
		return w;
	if (cnt < M / 2)
		cnt++;
	else
		z = -1;
	if (!solve(x2 - x1, y2, x1, y1)) {
		if (z != -1)
			put(z, 1);
		return 1;
	}
	w = y1 > 0 && solve(x1 + c - x2, y1 - 1, x2, y2);
	if (z != -1)
		put(z, w);
	return w;
}
 
int main() {
	int t;
 
	init();
	scanf("%d%d", &c, &t);
	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 'put':
gradingserver.c:30:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   30 |  if (o >= 2 && (o & o - 1) == 0) {
      |                     ~~^~~
gradingserver.c: In function 'main':
gradingserver.c:100:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |  scanf("%d%d", &c, &t);
      |  ^~~~~~~~~~~~~~~~~~~~~
gradingserver.c:104:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |   scanf("%lld%lld%lld%lld", &x1, &y2, &x2, &y1), x1 -= y1 * c, x2 -= y2 * c;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 77 ms 157268 KB Output is correct
2 Correct 72 ms 157268 KB Output is correct
3 Correct 74 ms 157268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 157268 KB Output is correct
2 Correct 114 ms 158200 KB Output is correct
3 Correct 121 ms 159976 KB Output is correct
4 Correct 122 ms 164436 KB Output is correct
5 Correct 127 ms 164584 KB Output is correct
6 Correct 122 ms 164220 KB Output is correct
7 Correct 127 ms 162900 KB Output is correct
8 Correct 121 ms 161308 KB Output is correct
9 Correct 118 ms 158288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 157268 KB Output is correct
2 Correct 114 ms 158200 KB Output is correct
3 Correct 121 ms 159976 KB Output is correct
4 Correct 122 ms 164436 KB Output is correct
5 Correct 127 ms 164584 KB Output is correct
6 Correct 122 ms 164220 KB Output is correct
7 Correct 127 ms 162900 KB Output is correct
8 Correct 121 ms 161308 KB Output is correct
9 Correct 118 ms 158288 KB Output is correct
10 Correct 73 ms 157268 KB Output is correct
11 Correct 124 ms 158288 KB Output is correct
12 Correct 117 ms 159824 KB Output is correct
13 Correct 125 ms 164612 KB Output is correct
14 Correct 121 ms 164808 KB Output is correct
15 Correct 124 ms 164228 KB Output is correct
16 Correct 125 ms 162900 KB Output is correct
17 Correct 118 ms 161360 KB Output is correct
18 Correct 113 ms 158328 KB Output is correct
19 Correct 119 ms 158292 KB Output is correct
20 Correct 121 ms 159372 KB Output is correct
21 Correct 129 ms 165616 KB Output is correct
22 Correct 128 ms 165392 KB Output is correct
23 Correct 139 ms 165460 KB Output is correct
24 Correct 134 ms 165460 KB Output is correct
25 Correct 137 ms 165624 KB Output is correct
26 Correct 132 ms 162640 KB Output is correct
27 Correct 137 ms 165200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 158288 KB Output is correct
2 Correct 155 ms 158544 KB Output is correct
3 Correct 141 ms 158288 KB Output is correct
4 Correct 80 ms 157292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 157268 KB Output is correct
2 Correct 114 ms 158200 KB Output is correct
3 Correct 121 ms 159976 KB Output is correct
4 Correct 122 ms 164436 KB Output is correct
5 Correct 127 ms 164584 KB Output is correct
6 Correct 122 ms 164220 KB Output is correct
7 Correct 127 ms 162900 KB Output is correct
8 Correct 121 ms 161308 KB Output is correct
9 Correct 118 ms 158288 KB Output is correct
10 Correct 73 ms 157268 KB Output is correct
11 Correct 124 ms 158288 KB Output is correct
12 Correct 117 ms 159824 KB Output is correct
13 Correct 125 ms 164612 KB Output is correct
14 Correct 121 ms 164808 KB Output is correct
15 Correct 124 ms 164228 KB Output is correct
16 Correct 125 ms 162900 KB Output is correct
17 Correct 118 ms 161360 KB Output is correct
18 Correct 113 ms 158328 KB Output is correct
19 Correct 119 ms 158292 KB Output is correct
20 Correct 121 ms 159372 KB Output is correct
21 Correct 129 ms 165616 KB Output is correct
22 Correct 128 ms 165392 KB Output is correct
23 Correct 139 ms 165460 KB Output is correct
24 Correct 134 ms 165460 KB Output is correct
25 Correct 137 ms 165624 KB Output is correct
26 Correct 132 ms 162640 KB Output is correct
27 Correct 137 ms 165200 KB Output is correct
28 Correct 74 ms 157264 KB Output is correct
29 Correct 116 ms 158148 KB Output is correct
30 Correct 116 ms 159828 KB Output is correct
31 Correct 142 ms 164436 KB Output is correct
32 Correct 130 ms 164764 KB Output is correct
33 Correct 127 ms 164236 KB Output is correct
34 Correct 121 ms 162900 KB Output is correct
35 Correct 122 ms 161364 KB Output is correct
36 Correct 122 ms 158316 KB Output is correct
37 Correct 119 ms 158320 KB Output is correct
38 Correct 119 ms 159312 KB Output is correct
39 Correct 130 ms 165456 KB Output is correct
40 Correct 128 ms 165456 KB Output is correct
41 Correct 128 ms 165452 KB Output is correct
42 Correct 136 ms 165460 KB Output is correct
43 Correct 142 ms 165528 KB Output is correct
44 Correct 119 ms 162644 KB Output is correct
45 Correct 121 ms 165068 KB Output is correct
46 Correct 157 ms 165460 KB Output is correct
47 Correct 123 ms 158504 KB Output is correct
48 Correct 151 ms 165564 KB Output is correct
49 Correct 139 ms 165456 KB Output is correct
50 Correct 141 ms 165452 KB Output is correct
51 Correct 167 ms 165484 KB Output is correct
52 Correct 227 ms 166308 KB Output is correct
53 Correct 128 ms 165640 KB Output is correct
54 Correct 160 ms 165716 KB Output is correct
55 Correct 124 ms 161104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 157268 KB Output is correct
2 Correct 114 ms 158200 KB Output is correct
3 Correct 121 ms 159976 KB Output is correct
4 Correct 122 ms 164436 KB Output is correct
5 Correct 127 ms 164584 KB Output is correct
6 Correct 122 ms 164220 KB Output is correct
7 Correct 127 ms 162900 KB Output is correct
8 Correct 121 ms 161308 KB Output is correct
9 Correct 118 ms 158288 KB Output is correct
10 Correct 73 ms 157268 KB Output is correct
11 Correct 124 ms 158288 KB Output is correct
12 Correct 117 ms 159824 KB Output is correct
13 Correct 125 ms 164612 KB Output is correct
14 Correct 121 ms 164808 KB Output is correct
15 Correct 124 ms 164228 KB Output is correct
16 Correct 125 ms 162900 KB Output is correct
17 Correct 118 ms 161360 KB Output is correct
18 Correct 113 ms 158328 KB Output is correct
19 Correct 119 ms 158292 KB Output is correct
20 Correct 121 ms 159372 KB Output is correct
21 Correct 129 ms 165616 KB Output is correct
22 Correct 128 ms 165392 KB Output is correct
23 Correct 139 ms 165460 KB Output is correct
24 Correct 134 ms 165460 KB Output is correct
25 Correct 137 ms 165624 KB Output is correct
26 Correct 132 ms 162640 KB Output is correct
27 Correct 137 ms 165200 KB Output is correct
28 Correct 140 ms 158288 KB Output is correct
29 Correct 155 ms 158544 KB Output is correct
30 Correct 141 ms 158288 KB Output is correct
31 Correct 80 ms 157292 KB Output is correct
32 Correct 147 ms 158288 KB Output is correct
33 Correct 143 ms 158296 KB Output is correct
34 Correct 140 ms 158288 KB Output is correct
35 Correct 74 ms 157268 KB Output is correct
36 Correct 77 ms 157404 KB Output is correct
37 Correct 114 ms 158288 KB Output is correct
38 Correct 118 ms 159828 KB Output is correct
39 Correct 121 ms 164432 KB Output is correct
40 Correct 119 ms 164688 KB Output is correct
41 Correct 140 ms 164176 KB Output is correct
42 Correct 132 ms 163152 KB Output is correct
43 Correct 116 ms 161588 KB Output is correct
44 Correct 120 ms 158240 KB Output is correct
45 Correct 120 ms 158292 KB Output is correct
46 Correct 122 ms 159316 KB Output is correct
47 Correct 133 ms 165460 KB Output is correct
48 Correct 132 ms 165460 KB Output is correct
49 Correct 125 ms 165500 KB Output is correct
50 Correct 133 ms 165548 KB Output is correct
51 Correct 139 ms 165628 KB Output is correct
52 Correct 119 ms 162628 KB Output is correct
53 Correct 120 ms 165204 KB Output is correct
54 Correct 74 ms 157268 KB Output is correct
55 Correct 136 ms 165864 KB Output is correct
56 Correct 154 ms 165712 KB Output is correct
57 Correct 148 ms 165632 KB Output is correct
58 Correct 121 ms 158292 KB Output is correct
59 Correct 155 ms 165464 KB Output is correct
60 Correct 147 ms 165416 KB Output is correct
61 Correct 148 ms 165460 KB Output is correct
62 Correct 161 ms 165456 KB Output is correct
63 Correct 146 ms 164176 KB Output is correct
64 Correct 149 ms 162128 KB Output is correct
65 Correct 164 ms 158544 KB Output is correct
66 Correct 153 ms 165460 KB Output is correct
67 Correct 151 ms 165456 KB Output is correct
68 Correct 151 ms 165460 KB Output is correct
69 Correct 188 ms 165716 KB Output is correct
70 Correct 309 ms 166224 KB Output is correct
71 Correct 927 ms 158292 KB Output is correct
72 Correct 192 ms 165716 KB Output is correct
73 Correct 143 ms 159572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 157268 KB Output is correct
2 Correct 114 ms 158200 KB Output is correct
3 Correct 121 ms 159976 KB Output is correct
4 Correct 122 ms 164436 KB Output is correct
5 Correct 127 ms 164584 KB Output is correct
6 Correct 122 ms 164220 KB Output is correct
7 Correct 127 ms 162900 KB Output is correct
8 Correct 121 ms 161308 KB Output is correct
9 Correct 118 ms 158288 KB Output is correct
10 Correct 73 ms 157268 KB Output is correct
11 Correct 118 ms 158292 KB Output is correct
12 Correct 117 ms 159824 KB Output is correct
13 Correct 123 ms 164432 KB Output is correct
14 Correct 119 ms 164692 KB Output is correct
15 Correct 125 ms 164176 KB Output is correct
16 Correct 123 ms 162916 KB Output is correct
17 Correct 122 ms 161364 KB Output is correct
18 Correct 112 ms 158292 KB Output is correct
19 Correct 149 ms 165460 KB Output is correct
20 Correct 2951 ms 166992 KB Output is correct
21 Execution timed out 4066 ms 166484 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 157268 KB Output is correct
2 Correct 114 ms 158200 KB Output is correct
3 Correct 121 ms 159976 KB Output is correct
4 Correct 122 ms 164436 KB Output is correct
5 Correct 127 ms 164584 KB Output is correct
6 Correct 122 ms 164220 KB Output is correct
7 Correct 127 ms 162900 KB Output is correct
8 Correct 121 ms 161308 KB Output is correct
9 Correct 118 ms 158288 KB Output is correct
10 Correct 73 ms 157268 KB Output is correct
11 Correct 124 ms 158288 KB Output is correct
12 Correct 117 ms 159824 KB Output is correct
13 Correct 125 ms 164612 KB Output is correct
14 Correct 121 ms 164808 KB Output is correct
15 Correct 124 ms 164228 KB Output is correct
16 Correct 125 ms 162900 KB Output is correct
17 Correct 118 ms 161360 KB Output is correct
18 Correct 113 ms 158328 KB Output is correct
19 Correct 119 ms 158292 KB Output is correct
20 Correct 121 ms 159372 KB Output is correct
21 Correct 129 ms 165616 KB Output is correct
22 Correct 128 ms 165392 KB Output is correct
23 Correct 139 ms 165460 KB Output is correct
24 Correct 134 ms 165460 KB Output is correct
25 Correct 137 ms 165624 KB Output is correct
26 Correct 132 ms 162640 KB Output is correct
27 Correct 137 ms 165200 KB Output is correct
28 Correct 140 ms 158288 KB Output is correct
29 Correct 155 ms 158544 KB Output is correct
30 Correct 141 ms 158288 KB Output is correct
31 Correct 80 ms 157292 KB Output is correct
32 Correct 74 ms 157264 KB Output is correct
33 Correct 116 ms 158148 KB Output is correct
34 Correct 116 ms 159828 KB Output is correct
35 Correct 142 ms 164436 KB Output is correct
36 Correct 130 ms 164764 KB Output is correct
37 Correct 127 ms 164236 KB Output is correct
38 Correct 121 ms 162900 KB Output is correct
39 Correct 122 ms 161364 KB Output is correct
40 Correct 122 ms 158316 KB Output is correct
41 Correct 119 ms 158320 KB Output is correct
42 Correct 119 ms 159312 KB Output is correct
43 Correct 130 ms 165456 KB Output is correct
44 Correct 128 ms 165456 KB Output is correct
45 Correct 128 ms 165452 KB Output is correct
46 Correct 136 ms 165460 KB Output is correct
47 Correct 142 ms 165528 KB Output is correct
48 Correct 119 ms 162644 KB Output is correct
49 Correct 121 ms 165068 KB Output is correct
50 Correct 157 ms 165460 KB Output is correct
51 Correct 123 ms 158504 KB Output is correct
52 Correct 151 ms 165564 KB Output is correct
53 Correct 139 ms 165456 KB Output is correct
54 Correct 141 ms 165452 KB Output is correct
55 Correct 167 ms 165484 KB Output is correct
56 Correct 227 ms 166308 KB Output is correct
57 Correct 128 ms 165640 KB Output is correct
58 Correct 160 ms 165716 KB Output is correct
59 Correct 124 ms 161104 KB Output is correct
60 Correct 147 ms 158288 KB Output is correct
61 Correct 143 ms 158296 KB Output is correct
62 Correct 140 ms 158288 KB Output is correct
63 Correct 74 ms 157268 KB Output is correct
64 Correct 77 ms 157404 KB Output is correct
65 Correct 114 ms 158288 KB Output is correct
66 Correct 118 ms 159828 KB Output is correct
67 Correct 121 ms 164432 KB Output is correct
68 Correct 119 ms 164688 KB Output is correct
69 Correct 140 ms 164176 KB Output is correct
70 Correct 132 ms 163152 KB Output is correct
71 Correct 116 ms 161588 KB Output is correct
72 Correct 120 ms 158240 KB Output is correct
73 Correct 120 ms 158292 KB Output is correct
74 Correct 122 ms 159316 KB Output is correct
75 Correct 133 ms 165460 KB Output is correct
76 Correct 132 ms 165460 KB Output is correct
77 Correct 125 ms 165500 KB Output is correct
78 Correct 133 ms 165548 KB Output is correct
79 Correct 139 ms 165628 KB Output is correct
80 Correct 119 ms 162628 KB Output is correct
81 Correct 120 ms 165204 KB Output is correct
82 Correct 74 ms 157268 KB Output is correct
83 Correct 136 ms 165864 KB Output is correct
84 Correct 154 ms 165712 KB Output is correct
85 Correct 148 ms 165632 KB Output is correct
86 Correct 121 ms 158292 KB Output is correct
87 Correct 155 ms 165464 KB Output is correct
88 Correct 147 ms 165416 KB Output is correct
89 Correct 148 ms 165460 KB Output is correct
90 Correct 161 ms 165456 KB Output is correct
91 Correct 146 ms 164176 KB Output is correct
92 Correct 149 ms 162128 KB Output is correct
93 Correct 164 ms 158544 KB Output is correct
94 Correct 153 ms 165460 KB Output is correct
95 Correct 151 ms 165456 KB Output is correct
96 Correct 151 ms 165460 KB Output is correct
97 Correct 188 ms 165716 KB Output is correct
98 Correct 309 ms 166224 KB Output is correct
99 Correct 927 ms 158292 KB Output is correct
100 Correct 192 ms 165716 KB Output is correct
101 Correct 143 ms 159572 KB Output is correct
102 Correct 73 ms 157268 KB Output is correct
103 Correct 118 ms 158292 KB Output is correct
104 Correct 117 ms 159824 KB Output is correct
105 Correct 123 ms 164432 KB Output is correct
106 Correct 119 ms 164692 KB Output is correct
107 Correct 125 ms 164176 KB Output is correct
108 Correct 123 ms 162916 KB Output is correct
109 Correct 122 ms 161364 KB Output is correct
110 Correct 112 ms 158292 KB Output is correct
111 Correct 149 ms 165460 KB Output is correct
112 Correct 2951 ms 166992 KB Output is correct
113 Execution timed out 4066 ms 166484 KB Time limit exceeded
114 Halted 0 ms 0 KB -