Submission #1049498

# Submission time Handle Problem Language Result Execution time Memory
1049498 2024-08-08T19:40:41 Z rainboy Bring Down the Grading Server (CEOI23_gradingserver) C
65 / 100
4000 ms 5552 KB
#include <stdio.h>
#include <stdlib.h>
 
#define M	50000
#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 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 43 ms 4980 KB Output is correct
3 Correct 43 ms 5196 KB Output is correct
4 Correct 49 ms 5304 KB Output is correct
5 Correct 47 ms 5200 KB Output is correct
6 Correct 48 ms 5212 KB Output is correct
7 Correct 49 ms 5204 KB Output is correct
8 Correct 48 ms 5208 KB Output is correct
9 Correct 42 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 43 ms 4980 KB Output is correct
3 Correct 43 ms 5196 KB Output is correct
4 Correct 49 ms 5304 KB Output is correct
5 Correct 47 ms 5200 KB Output is correct
6 Correct 48 ms 5212 KB Output is correct
7 Correct 49 ms 5204 KB Output is correct
8 Correct 48 ms 5208 KB Output is correct
9 Correct 42 ms 5204 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 44 ms 5076 KB Output is correct
12 Correct 44 ms 5296 KB Output is correct
13 Correct 47 ms 5244 KB Output is correct
14 Correct 46 ms 5296 KB Output is correct
15 Correct 49 ms 5228 KB Output is correct
16 Correct 59 ms 5132 KB Output is correct
17 Correct 45 ms 5176 KB Output is correct
18 Correct 43 ms 5036 KB Output is correct
19 Correct 48 ms 5200 KB Output is correct
20 Correct 49 ms 5212 KB Output is correct
21 Correct 54 ms 5204 KB Output is correct
22 Correct 56 ms 5200 KB Output is correct
23 Correct 62 ms 5116 KB Output is correct
24 Correct 57 ms 5280 KB Output is correct
25 Correct 64 ms 5204 KB Output is correct
26 Correct 48 ms 5252 KB Output is correct
27 Correct 50 ms 5348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 5128 KB Output is correct
2 Correct 75 ms 5052 KB Output is correct
3 Correct 86 ms 4948 KB Output is correct
4 Correct 2 ms 4164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 43 ms 4980 KB Output is correct
3 Correct 43 ms 5196 KB Output is correct
4 Correct 49 ms 5304 KB Output is correct
5 Correct 47 ms 5200 KB Output is correct
6 Correct 48 ms 5212 KB Output is correct
7 Correct 49 ms 5204 KB Output is correct
8 Correct 48 ms 5208 KB Output is correct
9 Correct 42 ms 5204 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 44 ms 5076 KB Output is correct
12 Correct 44 ms 5296 KB Output is correct
13 Correct 47 ms 5244 KB Output is correct
14 Correct 46 ms 5296 KB Output is correct
15 Correct 49 ms 5228 KB Output is correct
16 Correct 59 ms 5132 KB Output is correct
17 Correct 45 ms 5176 KB Output is correct
18 Correct 43 ms 5036 KB Output is correct
19 Correct 48 ms 5200 KB Output is correct
20 Correct 49 ms 5212 KB Output is correct
21 Correct 54 ms 5204 KB Output is correct
22 Correct 56 ms 5200 KB Output is correct
23 Correct 62 ms 5116 KB Output is correct
24 Correct 57 ms 5280 KB Output is correct
25 Correct 64 ms 5204 KB Output is correct
26 Correct 48 ms 5252 KB Output is correct
27 Correct 50 ms 5348 KB Output is correct
28 Correct 2 ms 4188 KB Output is correct
29 Correct 52 ms 4960 KB Output is correct
30 Correct 51 ms 5252 KB Output is correct
31 Correct 47 ms 5328 KB Output is correct
32 Correct 49 ms 5340 KB Output is correct
33 Correct 55 ms 5136 KB Output is correct
34 Correct 49 ms 5152 KB Output is correct
35 Correct 60 ms 5376 KB Output is correct
36 Correct 48 ms 5124 KB Output is correct
37 Correct 51 ms 5004 KB Output is correct
38 Correct 52 ms 5172 KB Output is correct
39 Correct 64 ms 5140 KB Output is correct
40 Correct 66 ms 5304 KB Output is correct
41 Correct 61 ms 5332 KB Output is correct
42 Correct 70 ms 5420 KB Output is correct
43 Correct 68 ms 5224 KB Output is correct
44 Correct 54 ms 5240 KB Output is correct
45 Correct 56 ms 5208 KB Output is correct
46 Correct 95 ms 5180 KB Output is correct
47 Correct 51 ms 5156 KB Output is correct
48 Correct 118 ms 5248 KB Output is correct
49 Correct 62 ms 5168 KB Output is correct
50 Correct 68 ms 5252 KB Output is correct
51 Correct 86 ms 5356 KB Output is correct
52 Correct 72 ms 5448 KB Output is correct
53 Correct 61 ms 5432 KB Output is correct
54 Correct 64 ms 5268 KB Output is correct
55 Correct 60 ms 5256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 43 ms 4980 KB Output is correct
3 Correct 43 ms 5196 KB Output is correct
4 Correct 49 ms 5304 KB Output is correct
5 Correct 47 ms 5200 KB Output is correct
6 Correct 48 ms 5212 KB Output is correct
7 Correct 49 ms 5204 KB Output is correct
8 Correct 48 ms 5208 KB Output is correct
9 Correct 42 ms 5204 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 44 ms 5076 KB Output is correct
12 Correct 44 ms 5296 KB Output is correct
13 Correct 47 ms 5244 KB Output is correct
14 Correct 46 ms 5296 KB Output is correct
15 Correct 49 ms 5228 KB Output is correct
16 Correct 59 ms 5132 KB Output is correct
17 Correct 45 ms 5176 KB Output is correct
18 Correct 43 ms 5036 KB Output is correct
19 Correct 48 ms 5200 KB Output is correct
20 Correct 49 ms 5212 KB Output is correct
21 Correct 54 ms 5204 KB Output is correct
22 Correct 56 ms 5200 KB Output is correct
23 Correct 62 ms 5116 KB Output is correct
24 Correct 57 ms 5280 KB Output is correct
25 Correct 64 ms 5204 KB Output is correct
26 Correct 48 ms 5252 KB Output is correct
27 Correct 50 ms 5348 KB Output is correct
28 Correct 78 ms 5128 KB Output is correct
29 Correct 75 ms 5052 KB Output is correct
30 Correct 86 ms 4948 KB Output is correct
31 Correct 2 ms 4164 KB Output is correct
32 Correct 78 ms 4948 KB Output is correct
33 Correct 80 ms 5016 KB Output is correct
34 Correct 76 ms 4960 KB Output is correct
35 Correct 2 ms 4188 KB Output is correct
36 Correct 3 ms 4188 KB Output is correct
37 Correct 63 ms 5064 KB Output is correct
38 Correct 53 ms 5248 KB Output is correct
39 Correct 52 ms 5156 KB Output is correct
40 Correct 46 ms 5296 KB Output is correct
41 Correct 50 ms 5200 KB Output is correct
42 Correct 55 ms 5220 KB Output is correct
43 Correct 47 ms 5288 KB Output is correct
44 Correct 43 ms 5248 KB Output is correct
45 Correct 50 ms 5204 KB Output is correct
46 Correct 50 ms 5324 KB Output is correct
47 Correct 57 ms 5212 KB Output is correct
48 Correct 51 ms 5208 KB Output is correct
49 Correct 51 ms 5180 KB Output is correct
50 Correct 54 ms 5352 KB Output is correct
51 Correct 62 ms 5400 KB Output is correct
52 Correct 71 ms 5260 KB Output is correct
53 Correct 49 ms 5228 KB Output is correct
54 Correct 2 ms 4188 KB Output is correct
55 Correct 49 ms 5552 KB Output is correct
56 Correct 58 ms 5452 KB Output is correct
57 Correct 93 ms 5204 KB Output is correct
58 Correct 55 ms 5208 KB Output is correct
59 Correct 124 ms 5440 KB Output is correct
60 Correct 110 ms 5204 KB Output is correct
61 Correct 81 ms 5216 KB Output is correct
62 Correct 77 ms 5208 KB Output is correct
63 Correct 81 ms 5260 KB Output is correct
64 Correct 74 ms 5204 KB Output is correct
65 Correct 73 ms 5240 KB Output is correct
66 Correct 469 ms 5304 KB Output is correct
67 Correct 502 ms 5348 KB Output is correct
68 Correct 75 ms 5204 KB Output is correct
69 Correct 117 ms 5340 KB Output is correct
70 Correct 169 ms 5404 KB Output is correct
71 Correct 885 ms 5200 KB Output is correct
72 Correct 154 ms 5200 KB Output is correct
73 Correct 57 ms 5160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 43 ms 4980 KB Output is correct
3 Correct 43 ms 5196 KB Output is correct
4 Correct 49 ms 5304 KB Output is correct
5 Correct 47 ms 5200 KB Output is correct
6 Correct 48 ms 5212 KB Output is correct
7 Correct 49 ms 5204 KB Output is correct
8 Correct 48 ms 5208 KB Output is correct
9 Correct 42 ms 5204 KB Output is correct
10 Correct 2 ms 4184 KB Output is correct
11 Correct 55 ms 5200 KB Output is correct
12 Correct 44 ms 5204 KB Output is correct
13 Correct 87 ms 5200 KB Output is correct
14 Correct 46 ms 5352 KB Output is correct
15 Correct 48 ms 5204 KB Output is correct
16 Correct 48 ms 5204 KB Output is correct
17 Correct 47 ms 5212 KB Output is correct
18 Correct 41 ms 5204 KB Output is correct
19 Correct 69 ms 5380 KB Output is correct
20 Correct 1797 ms 5232 KB Output is correct
21 Correct 3066 ms 5324 KB Output is correct
22 Correct 3724 ms 5340 KB Output is correct
23 Correct 910 ms 5288 KB Output is correct
24 Correct 991 ms 5460 KB Output is correct
25 Correct 285 ms 5460 KB Output is correct
26 Correct 78 ms 5200 KB Output is correct
27 Correct 3441 ms 5420 KB Output is correct
28 Execution timed out 4069 ms 4908 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 43 ms 4980 KB Output is correct
3 Correct 43 ms 5196 KB Output is correct
4 Correct 49 ms 5304 KB Output is correct
5 Correct 47 ms 5200 KB Output is correct
6 Correct 48 ms 5212 KB Output is correct
7 Correct 49 ms 5204 KB Output is correct
8 Correct 48 ms 5208 KB Output is correct
9 Correct 42 ms 5204 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 44 ms 5076 KB Output is correct
12 Correct 44 ms 5296 KB Output is correct
13 Correct 47 ms 5244 KB Output is correct
14 Correct 46 ms 5296 KB Output is correct
15 Correct 49 ms 5228 KB Output is correct
16 Correct 59 ms 5132 KB Output is correct
17 Correct 45 ms 5176 KB Output is correct
18 Correct 43 ms 5036 KB Output is correct
19 Correct 48 ms 5200 KB Output is correct
20 Correct 49 ms 5212 KB Output is correct
21 Correct 54 ms 5204 KB Output is correct
22 Correct 56 ms 5200 KB Output is correct
23 Correct 62 ms 5116 KB Output is correct
24 Correct 57 ms 5280 KB Output is correct
25 Correct 64 ms 5204 KB Output is correct
26 Correct 48 ms 5252 KB Output is correct
27 Correct 50 ms 5348 KB Output is correct
28 Correct 78 ms 5128 KB Output is correct
29 Correct 75 ms 5052 KB Output is correct
30 Correct 86 ms 4948 KB Output is correct
31 Correct 2 ms 4164 KB Output is correct
32 Correct 2 ms 4188 KB Output is correct
33 Correct 52 ms 4960 KB Output is correct
34 Correct 51 ms 5252 KB Output is correct
35 Correct 47 ms 5328 KB Output is correct
36 Correct 49 ms 5340 KB Output is correct
37 Correct 55 ms 5136 KB Output is correct
38 Correct 49 ms 5152 KB Output is correct
39 Correct 60 ms 5376 KB Output is correct
40 Correct 48 ms 5124 KB Output is correct
41 Correct 51 ms 5004 KB Output is correct
42 Correct 52 ms 5172 KB Output is correct
43 Correct 64 ms 5140 KB Output is correct
44 Correct 66 ms 5304 KB Output is correct
45 Correct 61 ms 5332 KB Output is correct
46 Correct 70 ms 5420 KB Output is correct
47 Correct 68 ms 5224 KB Output is correct
48 Correct 54 ms 5240 KB Output is correct
49 Correct 56 ms 5208 KB Output is correct
50 Correct 95 ms 5180 KB Output is correct
51 Correct 51 ms 5156 KB Output is correct
52 Correct 118 ms 5248 KB Output is correct
53 Correct 62 ms 5168 KB Output is correct
54 Correct 68 ms 5252 KB Output is correct
55 Correct 86 ms 5356 KB Output is correct
56 Correct 72 ms 5448 KB Output is correct
57 Correct 61 ms 5432 KB Output is correct
58 Correct 64 ms 5268 KB Output is correct
59 Correct 60 ms 5256 KB Output is correct
60 Correct 78 ms 4948 KB Output is correct
61 Correct 80 ms 5016 KB Output is correct
62 Correct 76 ms 4960 KB Output is correct
63 Correct 2 ms 4188 KB Output is correct
64 Correct 3 ms 4188 KB Output is correct
65 Correct 63 ms 5064 KB Output is correct
66 Correct 53 ms 5248 KB Output is correct
67 Correct 52 ms 5156 KB Output is correct
68 Correct 46 ms 5296 KB Output is correct
69 Correct 50 ms 5200 KB Output is correct
70 Correct 55 ms 5220 KB Output is correct
71 Correct 47 ms 5288 KB Output is correct
72 Correct 43 ms 5248 KB Output is correct
73 Correct 50 ms 5204 KB Output is correct
74 Correct 50 ms 5324 KB Output is correct
75 Correct 57 ms 5212 KB Output is correct
76 Correct 51 ms 5208 KB Output is correct
77 Correct 51 ms 5180 KB Output is correct
78 Correct 54 ms 5352 KB Output is correct
79 Correct 62 ms 5400 KB Output is correct
80 Correct 71 ms 5260 KB Output is correct
81 Correct 49 ms 5228 KB Output is correct
82 Correct 2 ms 4188 KB Output is correct
83 Correct 49 ms 5552 KB Output is correct
84 Correct 58 ms 5452 KB Output is correct
85 Correct 93 ms 5204 KB Output is correct
86 Correct 55 ms 5208 KB Output is correct
87 Correct 124 ms 5440 KB Output is correct
88 Correct 110 ms 5204 KB Output is correct
89 Correct 81 ms 5216 KB Output is correct
90 Correct 77 ms 5208 KB Output is correct
91 Correct 81 ms 5260 KB Output is correct
92 Correct 74 ms 5204 KB Output is correct
93 Correct 73 ms 5240 KB Output is correct
94 Correct 469 ms 5304 KB Output is correct
95 Correct 502 ms 5348 KB Output is correct
96 Correct 75 ms 5204 KB Output is correct
97 Correct 117 ms 5340 KB Output is correct
98 Correct 169 ms 5404 KB Output is correct
99 Correct 885 ms 5200 KB Output is correct
100 Correct 154 ms 5200 KB Output is correct
101 Correct 57 ms 5160 KB Output is correct
102 Correct 2 ms 4184 KB Output is correct
103 Correct 55 ms 5200 KB Output is correct
104 Correct 44 ms 5204 KB Output is correct
105 Correct 87 ms 5200 KB Output is correct
106 Correct 46 ms 5352 KB Output is correct
107 Correct 48 ms 5204 KB Output is correct
108 Correct 48 ms 5204 KB Output is correct
109 Correct 47 ms 5212 KB Output is correct
110 Correct 41 ms 5204 KB Output is correct
111 Correct 69 ms 5380 KB Output is correct
112 Correct 1797 ms 5232 KB Output is correct
113 Correct 3066 ms 5324 KB Output is correct
114 Correct 3724 ms 5340 KB Output is correct
115 Correct 910 ms 5288 KB Output is correct
116 Correct 991 ms 5460 KB Output is correct
117 Correct 285 ms 5460 KB Output is correct
118 Correct 78 ms 5200 KB Output is correct
119 Correct 3441 ms 5420 KB Output is correct
120 Execution timed out 4069 ms 4908 KB Time limit exceeded
121 Halted 0 ms 0 KB -