답안 #1049497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049497 2024-08-08T19:39:42 Z rainboy Bring Down the Grading Server (CEOI23_gradingserver) C
65 / 100
4000 ms 84048 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 / 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;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 79188 KB Output is correct
2 Correct 37 ms 79184 KB Output is correct
3 Correct 38 ms 79192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 79368 KB Output is correct
2 Correct 78 ms 80208 KB Output is correct
3 Correct 79 ms 81232 KB Output is correct
4 Correct 96 ms 83224 KB Output is correct
5 Correct 91 ms 83272 KB Output is correct
6 Correct 87 ms 83092 KB Output is correct
7 Correct 84 ms 82768 KB Output is correct
8 Correct 83 ms 82320 KB Output is correct
9 Correct 77 ms 80296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 79368 KB Output is correct
2 Correct 78 ms 80208 KB Output is correct
3 Correct 79 ms 81232 KB Output is correct
4 Correct 96 ms 83224 KB Output is correct
5 Correct 91 ms 83272 KB Output is correct
6 Correct 87 ms 83092 KB Output is correct
7 Correct 84 ms 82768 KB Output is correct
8 Correct 83 ms 82320 KB Output is correct
9 Correct 77 ms 80296 KB Output is correct
10 Correct 37 ms 79188 KB Output is correct
11 Correct 83 ms 80208 KB Output is correct
12 Correct 93 ms 81232 KB Output is correct
13 Correct 88 ms 83284 KB Output is correct
14 Correct 86 ms 83344 KB Output is correct
15 Correct 87 ms 83060 KB Output is correct
16 Correct 87 ms 82952 KB Output is correct
17 Correct 86 ms 82256 KB Output is correct
18 Correct 80 ms 80208 KB Output is correct
19 Correct 91 ms 80212 KB Output is correct
20 Correct 86 ms 80980 KB Output is correct
21 Correct 92 ms 83308 KB Output is correct
22 Correct 91 ms 83280 KB Output is correct
23 Correct 91 ms 83280 KB Output is correct
24 Correct 100 ms 83284 KB Output is correct
25 Correct 119 ms 83312 KB Output is correct
26 Correct 95 ms 83048 KB Output is correct
27 Correct 85 ms 83456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 80064 KB Output is correct
2 Correct 107 ms 80304 KB Output is correct
3 Correct 107 ms 80088 KB Output is correct
4 Correct 39 ms 79188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 79368 KB Output is correct
2 Correct 78 ms 80208 KB Output is correct
3 Correct 79 ms 81232 KB Output is correct
4 Correct 96 ms 83224 KB Output is correct
5 Correct 91 ms 83272 KB Output is correct
6 Correct 87 ms 83092 KB Output is correct
7 Correct 84 ms 82768 KB Output is correct
8 Correct 83 ms 82320 KB Output is correct
9 Correct 77 ms 80296 KB Output is correct
10 Correct 37 ms 79188 KB Output is correct
11 Correct 83 ms 80208 KB Output is correct
12 Correct 93 ms 81232 KB Output is correct
13 Correct 88 ms 83284 KB Output is correct
14 Correct 86 ms 83344 KB Output is correct
15 Correct 87 ms 83060 KB Output is correct
16 Correct 87 ms 82952 KB Output is correct
17 Correct 86 ms 82256 KB Output is correct
18 Correct 80 ms 80208 KB Output is correct
19 Correct 91 ms 80212 KB Output is correct
20 Correct 86 ms 80980 KB Output is correct
21 Correct 92 ms 83308 KB Output is correct
22 Correct 91 ms 83280 KB Output is correct
23 Correct 91 ms 83280 KB Output is correct
24 Correct 100 ms 83284 KB Output is correct
25 Correct 119 ms 83312 KB Output is correct
26 Correct 95 ms 83048 KB Output is correct
27 Correct 85 ms 83456 KB Output is correct
28 Correct 39 ms 79184 KB Output is correct
29 Correct 82 ms 80212 KB Output is correct
30 Correct 83 ms 81232 KB Output is correct
31 Correct 86 ms 83284 KB Output is correct
32 Correct 83 ms 83280 KB Output is correct
33 Correct 87 ms 83028 KB Output is correct
34 Correct 87 ms 82772 KB Output is correct
35 Correct 90 ms 82256 KB Output is correct
36 Correct 78 ms 80344 KB Output is correct
37 Correct 89 ms 80212 KB Output is correct
38 Correct 91 ms 80980 KB Output is correct
39 Correct 95 ms 83404 KB Output is correct
40 Correct 93 ms 83280 KB Output is correct
41 Correct 90 ms 83284 KB Output is correct
42 Correct 94 ms 83280 KB Output is correct
43 Correct 101 ms 83300 KB Output is correct
44 Correct 82 ms 83024 KB Output is correct
45 Correct 84 ms 83280 KB Output is correct
46 Correct 105 ms 83280 KB Output is correct
47 Correct 92 ms 80376 KB Output is correct
48 Correct 120 ms 83796 KB Output is correct
49 Correct 101 ms 83304 KB Output is correct
50 Correct 111 ms 83280 KB Output is correct
51 Correct 113 ms 83364 KB Output is correct
52 Correct 154 ms 84048 KB Output is correct
53 Correct 89 ms 83612 KB Output is correct
54 Correct 133 ms 83536 KB Output is correct
55 Correct 91 ms 82148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 79368 KB Output is correct
2 Correct 78 ms 80208 KB Output is correct
3 Correct 79 ms 81232 KB Output is correct
4 Correct 96 ms 83224 KB Output is correct
5 Correct 91 ms 83272 KB Output is correct
6 Correct 87 ms 83092 KB Output is correct
7 Correct 84 ms 82768 KB Output is correct
8 Correct 83 ms 82320 KB Output is correct
9 Correct 77 ms 80296 KB Output is correct
10 Correct 37 ms 79188 KB Output is correct
11 Correct 83 ms 80208 KB Output is correct
12 Correct 93 ms 81232 KB Output is correct
13 Correct 88 ms 83284 KB Output is correct
14 Correct 86 ms 83344 KB Output is correct
15 Correct 87 ms 83060 KB Output is correct
16 Correct 87 ms 82952 KB Output is correct
17 Correct 86 ms 82256 KB Output is correct
18 Correct 80 ms 80208 KB Output is correct
19 Correct 91 ms 80212 KB Output is correct
20 Correct 86 ms 80980 KB Output is correct
21 Correct 92 ms 83308 KB Output is correct
22 Correct 91 ms 83280 KB Output is correct
23 Correct 91 ms 83280 KB Output is correct
24 Correct 100 ms 83284 KB Output is correct
25 Correct 119 ms 83312 KB Output is correct
26 Correct 95 ms 83048 KB Output is correct
27 Correct 85 ms 83456 KB Output is correct
28 Correct 109 ms 80064 KB Output is correct
29 Correct 107 ms 80304 KB Output is correct
30 Correct 107 ms 80088 KB Output is correct
31 Correct 39 ms 79188 KB Output is correct
32 Correct 107 ms 80044 KB Output is correct
33 Correct 106 ms 80052 KB Output is correct
34 Correct 105 ms 80076 KB Output is correct
35 Correct 40 ms 79184 KB Output is correct
36 Correct 43 ms 79184 KB Output is correct
37 Correct 80 ms 80212 KB Output is correct
38 Correct 80 ms 81360 KB Output is correct
39 Correct 91 ms 83300 KB Output is correct
40 Correct 84 ms 83344 KB Output is correct
41 Correct 102 ms 83028 KB Output is correct
42 Correct 83 ms 82772 KB Output is correct
43 Correct 81 ms 82260 KB Output is correct
44 Correct 89 ms 80208 KB Output is correct
45 Correct 84 ms 80212 KB Output is correct
46 Correct 85 ms 80980 KB Output is correct
47 Correct 94 ms 83416 KB Output is correct
48 Correct 95 ms 83248 KB Output is correct
49 Correct 89 ms 83300 KB Output is correct
50 Correct 94 ms 83404 KB Output is correct
51 Correct 101 ms 83280 KB Output is correct
52 Correct 88 ms 83016 KB Output is correct
53 Correct 84 ms 83400 KB Output is correct
54 Correct 40 ms 79344 KB Output is correct
55 Correct 94 ms 83536 KB Output is correct
56 Correct 124 ms 83648 KB Output is correct
57 Correct 108 ms 83336 KB Output is correct
58 Correct 89 ms 80168 KB Output is correct
59 Correct 110 ms 83796 KB Output is correct
60 Correct 118 ms 83284 KB Output is correct
61 Correct 121 ms 83284 KB Output is correct
62 Correct 114 ms 83280 KB Output is correct
63 Correct 115 ms 83284 KB Output is correct
64 Correct 118 ms 82972 KB Output is correct
65 Correct 112 ms 80296 KB Output is correct
66 Correct 107 ms 83284 KB Output is correct
67 Correct 121 ms 83384 KB Output is correct
68 Correct 112 ms 83536 KB Output is correct
69 Correct 143 ms 84048 KB Output is correct
70 Correct 213 ms 83792 KB Output is correct
71 Correct 916 ms 80284 KB Output is correct
72 Correct 131 ms 83540 KB Output is correct
73 Correct 94 ms 81292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 79368 KB Output is correct
2 Correct 78 ms 80208 KB Output is correct
3 Correct 79 ms 81232 KB Output is correct
4 Correct 96 ms 83224 KB Output is correct
5 Correct 91 ms 83272 KB Output is correct
6 Correct 87 ms 83092 KB Output is correct
7 Correct 84 ms 82768 KB Output is correct
8 Correct 83 ms 82320 KB Output is correct
9 Correct 77 ms 80296 KB Output is correct
10 Correct 37 ms 79244 KB Output is correct
11 Correct 78 ms 80212 KB Output is correct
12 Correct 82 ms 81236 KB Output is correct
13 Correct 94 ms 83536 KB Output is correct
14 Correct 88 ms 83284 KB Output is correct
15 Correct 87 ms 83024 KB Output is correct
16 Correct 86 ms 82776 KB Output is correct
17 Correct 90 ms 82396 KB Output is correct
18 Correct 79 ms 80172 KB Output is correct
19 Correct 102 ms 83280 KB Output is correct
20 Correct 2638 ms 83904 KB Output is correct
21 Execution timed out 4049 ms 83872 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 79368 KB Output is correct
2 Correct 78 ms 80208 KB Output is correct
3 Correct 79 ms 81232 KB Output is correct
4 Correct 96 ms 83224 KB Output is correct
5 Correct 91 ms 83272 KB Output is correct
6 Correct 87 ms 83092 KB Output is correct
7 Correct 84 ms 82768 KB Output is correct
8 Correct 83 ms 82320 KB Output is correct
9 Correct 77 ms 80296 KB Output is correct
10 Correct 37 ms 79188 KB Output is correct
11 Correct 83 ms 80208 KB Output is correct
12 Correct 93 ms 81232 KB Output is correct
13 Correct 88 ms 83284 KB Output is correct
14 Correct 86 ms 83344 KB Output is correct
15 Correct 87 ms 83060 KB Output is correct
16 Correct 87 ms 82952 KB Output is correct
17 Correct 86 ms 82256 KB Output is correct
18 Correct 80 ms 80208 KB Output is correct
19 Correct 91 ms 80212 KB Output is correct
20 Correct 86 ms 80980 KB Output is correct
21 Correct 92 ms 83308 KB Output is correct
22 Correct 91 ms 83280 KB Output is correct
23 Correct 91 ms 83280 KB Output is correct
24 Correct 100 ms 83284 KB Output is correct
25 Correct 119 ms 83312 KB Output is correct
26 Correct 95 ms 83048 KB Output is correct
27 Correct 85 ms 83456 KB Output is correct
28 Correct 109 ms 80064 KB Output is correct
29 Correct 107 ms 80304 KB Output is correct
30 Correct 107 ms 80088 KB Output is correct
31 Correct 39 ms 79188 KB Output is correct
32 Correct 39 ms 79184 KB Output is correct
33 Correct 82 ms 80212 KB Output is correct
34 Correct 83 ms 81232 KB Output is correct
35 Correct 86 ms 83284 KB Output is correct
36 Correct 83 ms 83280 KB Output is correct
37 Correct 87 ms 83028 KB Output is correct
38 Correct 87 ms 82772 KB Output is correct
39 Correct 90 ms 82256 KB Output is correct
40 Correct 78 ms 80344 KB Output is correct
41 Correct 89 ms 80212 KB Output is correct
42 Correct 91 ms 80980 KB Output is correct
43 Correct 95 ms 83404 KB Output is correct
44 Correct 93 ms 83280 KB Output is correct
45 Correct 90 ms 83284 KB Output is correct
46 Correct 94 ms 83280 KB Output is correct
47 Correct 101 ms 83300 KB Output is correct
48 Correct 82 ms 83024 KB Output is correct
49 Correct 84 ms 83280 KB Output is correct
50 Correct 105 ms 83280 KB Output is correct
51 Correct 92 ms 80376 KB Output is correct
52 Correct 120 ms 83796 KB Output is correct
53 Correct 101 ms 83304 KB Output is correct
54 Correct 111 ms 83280 KB Output is correct
55 Correct 113 ms 83364 KB Output is correct
56 Correct 154 ms 84048 KB Output is correct
57 Correct 89 ms 83612 KB Output is correct
58 Correct 133 ms 83536 KB Output is correct
59 Correct 91 ms 82148 KB Output is correct
60 Correct 107 ms 80044 KB Output is correct
61 Correct 106 ms 80052 KB Output is correct
62 Correct 105 ms 80076 KB Output is correct
63 Correct 40 ms 79184 KB Output is correct
64 Correct 43 ms 79184 KB Output is correct
65 Correct 80 ms 80212 KB Output is correct
66 Correct 80 ms 81360 KB Output is correct
67 Correct 91 ms 83300 KB Output is correct
68 Correct 84 ms 83344 KB Output is correct
69 Correct 102 ms 83028 KB Output is correct
70 Correct 83 ms 82772 KB Output is correct
71 Correct 81 ms 82260 KB Output is correct
72 Correct 89 ms 80208 KB Output is correct
73 Correct 84 ms 80212 KB Output is correct
74 Correct 85 ms 80980 KB Output is correct
75 Correct 94 ms 83416 KB Output is correct
76 Correct 95 ms 83248 KB Output is correct
77 Correct 89 ms 83300 KB Output is correct
78 Correct 94 ms 83404 KB Output is correct
79 Correct 101 ms 83280 KB Output is correct
80 Correct 88 ms 83016 KB Output is correct
81 Correct 84 ms 83400 KB Output is correct
82 Correct 40 ms 79344 KB Output is correct
83 Correct 94 ms 83536 KB Output is correct
84 Correct 124 ms 83648 KB Output is correct
85 Correct 108 ms 83336 KB Output is correct
86 Correct 89 ms 80168 KB Output is correct
87 Correct 110 ms 83796 KB Output is correct
88 Correct 118 ms 83284 KB Output is correct
89 Correct 121 ms 83284 KB Output is correct
90 Correct 114 ms 83280 KB Output is correct
91 Correct 115 ms 83284 KB Output is correct
92 Correct 118 ms 82972 KB Output is correct
93 Correct 112 ms 80296 KB Output is correct
94 Correct 107 ms 83284 KB Output is correct
95 Correct 121 ms 83384 KB Output is correct
96 Correct 112 ms 83536 KB Output is correct
97 Correct 143 ms 84048 KB Output is correct
98 Correct 213 ms 83792 KB Output is correct
99 Correct 916 ms 80284 KB Output is correct
100 Correct 131 ms 83540 KB Output is correct
101 Correct 94 ms 81292 KB Output is correct
102 Correct 37 ms 79244 KB Output is correct
103 Correct 78 ms 80212 KB Output is correct
104 Correct 82 ms 81236 KB Output is correct
105 Correct 94 ms 83536 KB Output is correct
106 Correct 88 ms 83284 KB Output is correct
107 Correct 87 ms 83024 KB Output is correct
108 Correct 86 ms 82776 KB Output is correct
109 Correct 90 ms 82396 KB Output is correct
110 Correct 79 ms 80172 KB Output is correct
111 Correct 102 ms 83280 KB Output is correct
112 Correct 2638 ms 83904 KB Output is correct
113 Execution timed out 4049 ms 83872 KB Time limit exceeded
114 Halted 0 ms 0 KB -