답안 #1049494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049494 2024-08-08T19:36:38 Z rainboy Bring Down the Grading Server (CEOI23_gradingserver) C
65 / 100
4000 ms 87248 KB
#include <stdio.h>
#include <stdlib.h>
 
#define M	1000000
#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)
		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;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 79252 KB Output is correct
2 Correct 41 ms 79232 KB Output is correct
3 Correct 38 ms 79244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 79184 KB Output is correct
2 Correct 92 ms 80212 KB Output is correct
3 Correct 80 ms 81276 KB Output is correct
4 Correct 87 ms 83284 KB Output is correct
5 Correct 87 ms 83280 KB Output is correct
6 Correct 90 ms 83000 KB Output is correct
7 Correct 110 ms 82964 KB Output is correct
8 Correct 87 ms 82384 KB Output is correct
9 Correct 80 ms 80132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 79184 KB Output is correct
2 Correct 92 ms 80212 KB Output is correct
3 Correct 80 ms 81276 KB Output is correct
4 Correct 87 ms 83284 KB Output is correct
5 Correct 87 ms 83280 KB Output is correct
6 Correct 90 ms 83000 KB Output is correct
7 Correct 110 ms 82964 KB Output is correct
8 Correct 87 ms 82384 KB Output is correct
9 Correct 80 ms 80132 KB Output is correct
10 Correct 38 ms 79188 KB Output is correct
11 Correct 87 ms 80112 KB Output is correct
12 Correct 81 ms 81236 KB Output is correct
13 Correct 89 ms 83156 KB Output is correct
14 Correct 85 ms 83304 KB Output is correct
15 Correct 86 ms 83024 KB Output is correct
16 Correct 85 ms 82768 KB Output is correct
17 Correct 86 ms 82256 KB Output is correct
18 Correct 79 ms 80208 KB Output is correct
19 Correct 93 ms 80208 KB Output is correct
20 Correct 85 ms 80980 KB Output is correct
21 Correct 95 ms 83280 KB Output is correct
22 Correct 92 ms 83280 KB Output is correct
23 Correct 91 ms 83360 KB Output is correct
24 Correct 96 ms 83280 KB Output is correct
25 Correct 102 ms 83324 KB Output is correct
26 Correct 83 ms 83024 KB Output is correct
27 Correct 84 ms 83284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 80208 KB Output is correct
2 Correct 112 ms 80208 KB Output is correct
3 Correct 116 ms 80116 KB Output is correct
4 Correct 38 ms 79192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 79184 KB Output is correct
2 Correct 92 ms 80212 KB Output is correct
3 Correct 80 ms 81276 KB Output is correct
4 Correct 87 ms 83284 KB Output is correct
5 Correct 87 ms 83280 KB Output is correct
6 Correct 90 ms 83000 KB Output is correct
7 Correct 110 ms 82964 KB Output is correct
8 Correct 87 ms 82384 KB Output is correct
9 Correct 80 ms 80132 KB Output is correct
10 Correct 38 ms 79188 KB Output is correct
11 Correct 87 ms 80112 KB Output is correct
12 Correct 81 ms 81236 KB Output is correct
13 Correct 89 ms 83156 KB Output is correct
14 Correct 85 ms 83304 KB Output is correct
15 Correct 86 ms 83024 KB Output is correct
16 Correct 85 ms 82768 KB Output is correct
17 Correct 86 ms 82256 KB Output is correct
18 Correct 79 ms 80208 KB Output is correct
19 Correct 93 ms 80208 KB Output is correct
20 Correct 85 ms 80980 KB Output is correct
21 Correct 95 ms 83280 KB Output is correct
22 Correct 92 ms 83280 KB Output is correct
23 Correct 91 ms 83360 KB Output is correct
24 Correct 96 ms 83280 KB Output is correct
25 Correct 102 ms 83324 KB Output is correct
26 Correct 83 ms 83024 KB Output is correct
27 Correct 84 ms 83284 KB Output is correct
28 Correct 38 ms 79244 KB Output is correct
29 Correct 80 ms 80212 KB Output is correct
30 Correct 88 ms 81236 KB Output is correct
31 Correct 86 ms 83340 KB Output is correct
32 Correct 91 ms 83284 KB Output is correct
33 Correct 88 ms 83196 KB Output is correct
34 Correct 84 ms 82980 KB Output is correct
35 Correct 84 ms 82256 KB Output is correct
36 Correct 86 ms 80268 KB Output is correct
37 Correct 84 ms 80212 KB Output is correct
38 Correct 86 ms 81128 KB Output is correct
39 Correct 94 ms 83280 KB Output is correct
40 Correct 101 ms 83284 KB Output is correct
41 Correct 95 ms 83292 KB Output is correct
42 Correct 92 ms 83248 KB Output is correct
43 Correct 99 ms 83284 KB Output is correct
44 Correct 83 ms 83028 KB Output is correct
45 Correct 85 ms 83280 KB Output is correct
46 Correct 106 ms 83408 KB Output is correct
47 Correct 90 ms 80208 KB Output is correct
48 Correct 114 ms 83644 KB Output is correct
49 Correct 103 ms 83284 KB Output is correct
50 Correct 103 ms 83312 KB Output is correct
51 Correct 107 ms 83280 KB Output is correct
52 Correct 172 ms 85072 KB Output is correct
53 Correct 95 ms 83480 KB Output is correct
54 Correct 115 ms 83540 KB Output is correct
55 Correct 94 ms 82160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 79184 KB Output is correct
2 Correct 92 ms 80212 KB Output is correct
3 Correct 80 ms 81276 KB Output is correct
4 Correct 87 ms 83284 KB Output is correct
5 Correct 87 ms 83280 KB Output is correct
6 Correct 90 ms 83000 KB Output is correct
7 Correct 110 ms 82964 KB Output is correct
8 Correct 87 ms 82384 KB Output is correct
9 Correct 80 ms 80132 KB Output is correct
10 Correct 38 ms 79188 KB Output is correct
11 Correct 87 ms 80112 KB Output is correct
12 Correct 81 ms 81236 KB Output is correct
13 Correct 89 ms 83156 KB Output is correct
14 Correct 85 ms 83304 KB Output is correct
15 Correct 86 ms 83024 KB Output is correct
16 Correct 85 ms 82768 KB Output is correct
17 Correct 86 ms 82256 KB Output is correct
18 Correct 79 ms 80208 KB Output is correct
19 Correct 93 ms 80208 KB Output is correct
20 Correct 85 ms 80980 KB Output is correct
21 Correct 95 ms 83280 KB Output is correct
22 Correct 92 ms 83280 KB Output is correct
23 Correct 91 ms 83360 KB Output is correct
24 Correct 96 ms 83280 KB Output is correct
25 Correct 102 ms 83324 KB Output is correct
26 Correct 83 ms 83024 KB Output is correct
27 Correct 84 ms 83284 KB Output is correct
28 Correct 117 ms 80208 KB Output is correct
29 Correct 112 ms 80208 KB Output is correct
30 Correct 116 ms 80116 KB Output is correct
31 Correct 38 ms 79192 KB Output is correct
32 Correct 108 ms 80044 KB Output is correct
33 Correct 109 ms 80212 KB Output is correct
34 Correct 107 ms 80212 KB Output is correct
35 Correct 38 ms 79192 KB Output is correct
36 Correct 39 ms 79184 KB Output is correct
37 Correct 79 ms 80212 KB Output is correct
38 Correct 80 ms 81236 KB Output is correct
39 Correct 85 ms 83284 KB Output is correct
40 Correct 84 ms 83288 KB Output is correct
41 Correct 90 ms 83028 KB Output is correct
42 Correct 85 ms 82772 KB Output is correct
43 Correct 82 ms 82220 KB Output is correct
44 Correct 79 ms 80232 KB Output is correct
45 Correct 84 ms 80208 KB Output is correct
46 Correct 87 ms 81004 KB Output is correct
47 Correct 95 ms 83284 KB Output is correct
48 Correct 106 ms 83440 KB Output is correct
49 Correct 89 ms 83300 KB Output is correct
50 Correct 92 ms 83284 KB Output is correct
51 Correct 98 ms 83284 KB Output is correct
52 Correct 83 ms 83028 KB Output is correct
53 Correct 84 ms 83436 KB Output is correct
54 Correct 38 ms 79244 KB Output is correct
55 Correct 100 ms 83484 KB Output is correct
56 Correct 117 ms 83640 KB Output is correct
57 Correct 110 ms 83236 KB Output is correct
58 Correct 102 ms 80212 KB Output is correct
59 Correct 132 ms 83796 KB Output is correct
60 Correct 112 ms 83284 KB Output is correct
61 Correct 118 ms 83368 KB Output is correct
62 Correct 114 ms 83284 KB Output is correct
63 Correct 109 ms 83284 KB Output is correct
64 Correct 110 ms 82812 KB Output is correct
65 Correct 113 ms 80212 KB Output is correct
66 Correct 114 ms 83332 KB Output is correct
67 Correct 111 ms 83424 KB Output is correct
68 Correct 108 ms 83284 KB Output is correct
69 Correct 136 ms 84048 KB Output is correct
70 Correct 243 ms 85720 KB Output is correct
71 Correct 877 ms 80208 KB Output is correct
72 Correct 134 ms 83540 KB Output is correct
73 Correct 95 ms 81164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 79184 KB Output is correct
2 Correct 92 ms 80212 KB Output is correct
3 Correct 80 ms 81276 KB Output is correct
4 Correct 87 ms 83284 KB Output is correct
5 Correct 87 ms 83280 KB Output is correct
6 Correct 90 ms 83000 KB Output is correct
7 Correct 110 ms 82964 KB Output is correct
8 Correct 87 ms 82384 KB Output is correct
9 Correct 80 ms 80132 KB Output is correct
10 Correct 39 ms 79184 KB Output is correct
11 Correct 80 ms 80124 KB Output is correct
12 Correct 88 ms 81236 KB Output is correct
13 Correct 86 ms 83280 KB Output is correct
14 Correct 85 ms 83284 KB Output is correct
15 Correct 93 ms 83184 KB Output is correct
16 Correct 85 ms 82772 KB Output is correct
17 Correct 84 ms 82256 KB Output is correct
18 Correct 86 ms 80212 KB Output is correct
19 Correct 105 ms 83504 KB Output is correct
20 Correct 2904 ms 87248 KB Output is correct
21 Execution timed out 4038 ms 86900 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 79184 KB Output is correct
2 Correct 92 ms 80212 KB Output is correct
3 Correct 80 ms 81276 KB Output is correct
4 Correct 87 ms 83284 KB Output is correct
5 Correct 87 ms 83280 KB Output is correct
6 Correct 90 ms 83000 KB Output is correct
7 Correct 110 ms 82964 KB Output is correct
8 Correct 87 ms 82384 KB Output is correct
9 Correct 80 ms 80132 KB Output is correct
10 Correct 38 ms 79188 KB Output is correct
11 Correct 87 ms 80112 KB Output is correct
12 Correct 81 ms 81236 KB Output is correct
13 Correct 89 ms 83156 KB Output is correct
14 Correct 85 ms 83304 KB Output is correct
15 Correct 86 ms 83024 KB Output is correct
16 Correct 85 ms 82768 KB Output is correct
17 Correct 86 ms 82256 KB Output is correct
18 Correct 79 ms 80208 KB Output is correct
19 Correct 93 ms 80208 KB Output is correct
20 Correct 85 ms 80980 KB Output is correct
21 Correct 95 ms 83280 KB Output is correct
22 Correct 92 ms 83280 KB Output is correct
23 Correct 91 ms 83360 KB Output is correct
24 Correct 96 ms 83280 KB Output is correct
25 Correct 102 ms 83324 KB Output is correct
26 Correct 83 ms 83024 KB Output is correct
27 Correct 84 ms 83284 KB Output is correct
28 Correct 117 ms 80208 KB Output is correct
29 Correct 112 ms 80208 KB Output is correct
30 Correct 116 ms 80116 KB Output is correct
31 Correct 38 ms 79192 KB Output is correct
32 Correct 38 ms 79244 KB Output is correct
33 Correct 80 ms 80212 KB Output is correct
34 Correct 88 ms 81236 KB Output is correct
35 Correct 86 ms 83340 KB Output is correct
36 Correct 91 ms 83284 KB Output is correct
37 Correct 88 ms 83196 KB Output is correct
38 Correct 84 ms 82980 KB Output is correct
39 Correct 84 ms 82256 KB Output is correct
40 Correct 86 ms 80268 KB Output is correct
41 Correct 84 ms 80212 KB Output is correct
42 Correct 86 ms 81128 KB Output is correct
43 Correct 94 ms 83280 KB Output is correct
44 Correct 101 ms 83284 KB Output is correct
45 Correct 95 ms 83292 KB Output is correct
46 Correct 92 ms 83248 KB Output is correct
47 Correct 99 ms 83284 KB Output is correct
48 Correct 83 ms 83028 KB Output is correct
49 Correct 85 ms 83280 KB Output is correct
50 Correct 106 ms 83408 KB Output is correct
51 Correct 90 ms 80208 KB Output is correct
52 Correct 114 ms 83644 KB Output is correct
53 Correct 103 ms 83284 KB Output is correct
54 Correct 103 ms 83312 KB Output is correct
55 Correct 107 ms 83280 KB Output is correct
56 Correct 172 ms 85072 KB Output is correct
57 Correct 95 ms 83480 KB Output is correct
58 Correct 115 ms 83540 KB Output is correct
59 Correct 94 ms 82160 KB Output is correct
60 Correct 108 ms 80044 KB Output is correct
61 Correct 109 ms 80212 KB Output is correct
62 Correct 107 ms 80212 KB Output is correct
63 Correct 38 ms 79192 KB Output is correct
64 Correct 39 ms 79184 KB Output is correct
65 Correct 79 ms 80212 KB Output is correct
66 Correct 80 ms 81236 KB Output is correct
67 Correct 85 ms 83284 KB Output is correct
68 Correct 84 ms 83288 KB Output is correct
69 Correct 90 ms 83028 KB Output is correct
70 Correct 85 ms 82772 KB Output is correct
71 Correct 82 ms 82220 KB Output is correct
72 Correct 79 ms 80232 KB Output is correct
73 Correct 84 ms 80208 KB Output is correct
74 Correct 87 ms 81004 KB Output is correct
75 Correct 95 ms 83284 KB Output is correct
76 Correct 106 ms 83440 KB Output is correct
77 Correct 89 ms 83300 KB Output is correct
78 Correct 92 ms 83284 KB Output is correct
79 Correct 98 ms 83284 KB Output is correct
80 Correct 83 ms 83028 KB Output is correct
81 Correct 84 ms 83436 KB Output is correct
82 Correct 38 ms 79244 KB Output is correct
83 Correct 100 ms 83484 KB Output is correct
84 Correct 117 ms 83640 KB Output is correct
85 Correct 110 ms 83236 KB Output is correct
86 Correct 102 ms 80212 KB Output is correct
87 Correct 132 ms 83796 KB Output is correct
88 Correct 112 ms 83284 KB Output is correct
89 Correct 118 ms 83368 KB Output is correct
90 Correct 114 ms 83284 KB Output is correct
91 Correct 109 ms 83284 KB Output is correct
92 Correct 110 ms 82812 KB Output is correct
93 Correct 113 ms 80212 KB Output is correct
94 Correct 114 ms 83332 KB Output is correct
95 Correct 111 ms 83424 KB Output is correct
96 Correct 108 ms 83284 KB Output is correct
97 Correct 136 ms 84048 KB Output is correct
98 Correct 243 ms 85720 KB Output is correct
99 Correct 877 ms 80208 KB Output is correct
100 Correct 134 ms 83540 KB Output is correct
101 Correct 95 ms 81164 KB Output is correct
102 Correct 39 ms 79184 KB Output is correct
103 Correct 80 ms 80124 KB Output is correct
104 Correct 88 ms 81236 KB Output is correct
105 Correct 86 ms 83280 KB Output is correct
106 Correct 85 ms 83284 KB Output is correct
107 Correct 93 ms 83184 KB Output is correct
108 Correct 85 ms 82772 KB Output is correct
109 Correct 84 ms 82256 KB Output is correct
110 Correct 86 ms 80212 KB Output is correct
111 Correct 105 ms 83504 KB Output is correct
112 Correct 2904 ms 87248 KB Output is correct
113 Execution timed out 4038 ms 86900 KB Time limit exceeded
114 Halted 0 ms 0 KB -