답안 #1049495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049495 2024-08-08T19:37:53 Z rainboy Bring Down the Grading Server (CEOI23_gradingserver) C
65 / 100
4000 ms 27056 KB
#include <stdio.h>
#include <stdlib.h>
 
#define M	300000
#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 12 ms 23896 KB Output is correct
2 Correct 19 ms 23900 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 54 ms 24688 KB Output is correct
3 Correct 53 ms 25680 KB Output is correct
4 Correct 77 ms 25860 KB Output is correct
5 Correct 58 ms 25684 KB Output is correct
6 Correct 60 ms 25684 KB Output is correct
7 Correct 59 ms 25680 KB Output is correct
8 Correct 55 ms 25936 KB Output is correct
9 Correct 51 ms 24688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 54 ms 24688 KB Output is correct
3 Correct 53 ms 25680 KB Output is correct
4 Correct 77 ms 25860 KB Output is correct
5 Correct 58 ms 25684 KB Output is correct
6 Correct 60 ms 25684 KB Output is correct
7 Correct 59 ms 25680 KB Output is correct
8 Correct 55 ms 25936 KB Output is correct
9 Correct 51 ms 24688 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 61 ms 24660 KB Output is correct
12 Correct 53 ms 25684 KB Output is correct
13 Correct 57 ms 25684 KB Output is correct
14 Correct 56 ms 25680 KB Output is correct
15 Correct 58 ms 25684 KB Output is correct
16 Correct 63 ms 25704 KB Output is correct
17 Correct 55 ms 25748 KB Output is correct
18 Correct 51 ms 24656 KB Output is correct
19 Correct 58 ms 24652 KB Output is correct
20 Correct 59 ms 25532 KB Output is correct
21 Correct 65 ms 25680 KB Output is correct
22 Correct 61 ms 25680 KB Output is correct
23 Correct 62 ms 25688 KB Output is correct
24 Correct 63 ms 25936 KB Output is correct
25 Correct 73 ms 25936 KB Output is correct
26 Correct 62 ms 25876 KB Output is correct
27 Correct 63 ms 25940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 24656 KB Output is correct
2 Correct 82 ms 24656 KB Output is correct
3 Correct 79 ms 24660 KB Output is correct
4 Correct 12 ms 23896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 54 ms 24688 KB Output is correct
3 Correct 53 ms 25680 KB Output is correct
4 Correct 77 ms 25860 KB Output is correct
5 Correct 58 ms 25684 KB Output is correct
6 Correct 60 ms 25684 KB Output is correct
7 Correct 59 ms 25680 KB Output is correct
8 Correct 55 ms 25936 KB Output is correct
9 Correct 51 ms 24688 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 61 ms 24660 KB Output is correct
12 Correct 53 ms 25684 KB Output is correct
13 Correct 57 ms 25684 KB Output is correct
14 Correct 56 ms 25680 KB Output is correct
15 Correct 58 ms 25684 KB Output is correct
16 Correct 63 ms 25704 KB Output is correct
17 Correct 55 ms 25748 KB Output is correct
18 Correct 51 ms 24656 KB Output is correct
19 Correct 58 ms 24652 KB Output is correct
20 Correct 59 ms 25532 KB Output is correct
21 Correct 65 ms 25680 KB Output is correct
22 Correct 61 ms 25680 KB Output is correct
23 Correct 62 ms 25688 KB Output is correct
24 Correct 63 ms 25936 KB Output is correct
25 Correct 73 ms 25936 KB Output is correct
26 Correct 62 ms 25876 KB Output is correct
27 Correct 63 ms 25940 KB Output is correct
28 Correct 11 ms 23900 KB Output is correct
29 Correct 52 ms 24624 KB Output is correct
30 Correct 53 ms 25680 KB Output is correct
31 Correct 58 ms 25860 KB Output is correct
32 Correct 61 ms 25684 KB Output is correct
33 Correct 63 ms 25684 KB Output is correct
34 Correct 58 ms 25684 KB Output is correct
35 Correct 55 ms 25764 KB Output is correct
36 Correct 52 ms 24656 KB Output is correct
37 Correct 58 ms 24720 KB Output is correct
38 Correct 60 ms 25424 KB Output is correct
39 Correct 70 ms 25900 KB Output is correct
40 Correct 64 ms 25684 KB Output is correct
41 Correct 61 ms 25680 KB Output is correct
42 Correct 62 ms 25744 KB Output is correct
43 Correct 66 ms 25940 KB Output is correct
44 Correct 58 ms 25936 KB Output is correct
45 Correct 57 ms 25940 KB Output is correct
46 Correct 75 ms 25936 KB Output is correct
47 Correct 59 ms 24912 KB Output is correct
48 Correct 78 ms 26060 KB Output is correct
49 Correct 68 ms 25692 KB Output is correct
50 Correct 72 ms 25948 KB Output is correct
51 Correct 79 ms 25940 KB Output is correct
52 Correct 102 ms 26964 KB Output is correct
53 Correct 57 ms 25932 KB Output is correct
54 Correct 80 ms 26704 KB Output is correct
55 Correct 64 ms 25720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 54 ms 24688 KB Output is correct
3 Correct 53 ms 25680 KB Output is correct
4 Correct 77 ms 25860 KB Output is correct
5 Correct 58 ms 25684 KB Output is correct
6 Correct 60 ms 25684 KB Output is correct
7 Correct 59 ms 25680 KB Output is correct
8 Correct 55 ms 25936 KB Output is correct
9 Correct 51 ms 24688 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 61 ms 24660 KB Output is correct
12 Correct 53 ms 25684 KB Output is correct
13 Correct 57 ms 25684 KB Output is correct
14 Correct 56 ms 25680 KB Output is correct
15 Correct 58 ms 25684 KB Output is correct
16 Correct 63 ms 25704 KB Output is correct
17 Correct 55 ms 25748 KB Output is correct
18 Correct 51 ms 24656 KB Output is correct
19 Correct 58 ms 24652 KB Output is correct
20 Correct 59 ms 25532 KB Output is correct
21 Correct 65 ms 25680 KB Output is correct
22 Correct 61 ms 25680 KB Output is correct
23 Correct 62 ms 25688 KB Output is correct
24 Correct 63 ms 25936 KB Output is correct
25 Correct 73 ms 25936 KB Output is correct
26 Correct 62 ms 25876 KB Output is correct
27 Correct 63 ms 25940 KB Output is correct
28 Correct 81 ms 24656 KB Output is correct
29 Correct 82 ms 24656 KB Output is correct
30 Correct 79 ms 24660 KB Output is correct
31 Correct 12 ms 23896 KB Output is correct
32 Correct 79 ms 24660 KB Output is correct
33 Correct 78 ms 24656 KB Output is correct
34 Correct 81 ms 24552 KB Output is correct
35 Correct 12 ms 23900 KB Output is correct
36 Correct 13 ms 23900 KB Output is correct
37 Correct 53 ms 24660 KB Output is correct
38 Correct 54 ms 25676 KB Output is correct
39 Correct 59 ms 25680 KB Output is correct
40 Correct 57 ms 25676 KB Output is correct
41 Correct 67 ms 25680 KB Output is correct
42 Correct 57 ms 25712 KB Output is correct
43 Correct 55 ms 25688 KB Output is correct
44 Correct 51 ms 24660 KB Output is correct
45 Correct 60 ms 24720 KB Output is correct
46 Correct 86 ms 25424 KB Output is correct
47 Correct 70 ms 25888 KB Output is correct
48 Correct 69 ms 25916 KB Output is correct
49 Correct 64 ms 25804 KB Output is correct
50 Correct 65 ms 25936 KB Output is correct
51 Correct 68 ms 25940 KB Output is correct
52 Correct 56 ms 25832 KB Output is correct
53 Correct 57 ms 25940 KB Output is correct
54 Correct 12 ms 23900 KB Output is correct
55 Correct 60 ms 25892 KB Output is correct
56 Correct 80 ms 26776 KB Output is correct
57 Correct 76 ms 25960 KB Output is correct
58 Correct 62 ms 24916 KB Output is correct
59 Correct 85 ms 26220 KB Output is correct
60 Correct 85 ms 25936 KB Output is correct
61 Correct 84 ms 25684 KB Output is correct
62 Correct 85 ms 25744 KB Output is correct
63 Correct 83 ms 25684 KB Output is correct
64 Correct 83 ms 25936 KB Output is correct
65 Correct 81 ms 24968 KB Output is correct
66 Correct 74 ms 25988 KB Output is correct
67 Correct 74 ms 25940 KB Output is correct
68 Correct 88 ms 25816 KB Output is correct
69 Correct 99 ms 26196 KB Output is correct
70 Correct 162 ms 26960 KB Output is correct
71 Correct 867 ms 24780 KB Output is correct
72 Correct 101 ms 26452 KB Output is correct
73 Correct 67 ms 25424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 54 ms 24688 KB Output is correct
3 Correct 53 ms 25680 KB Output is correct
4 Correct 77 ms 25860 KB Output is correct
5 Correct 58 ms 25684 KB Output is correct
6 Correct 60 ms 25684 KB Output is correct
7 Correct 59 ms 25680 KB Output is correct
8 Correct 55 ms 25936 KB Output is correct
9 Correct 51 ms 24688 KB Output is correct
10 Correct 12 ms 23896 KB Output is correct
11 Correct 52 ms 24660 KB Output is correct
12 Correct 53 ms 25684 KB Output is correct
13 Correct 57 ms 25940 KB Output is correct
14 Correct 57 ms 25684 KB Output is correct
15 Correct 60 ms 25840 KB Output is correct
16 Correct 58 ms 25684 KB Output is correct
17 Correct 55 ms 25880 KB Output is correct
18 Correct 59 ms 24912 KB Output is correct
19 Correct 76 ms 25888 KB Output is correct
20 Correct 2281 ms 26988 KB Output is correct
21 Execution timed out 4048 ms 27056 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 54 ms 24688 KB Output is correct
3 Correct 53 ms 25680 KB Output is correct
4 Correct 77 ms 25860 KB Output is correct
5 Correct 58 ms 25684 KB Output is correct
6 Correct 60 ms 25684 KB Output is correct
7 Correct 59 ms 25680 KB Output is correct
8 Correct 55 ms 25936 KB Output is correct
9 Correct 51 ms 24688 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 61 ms 24660 KB Output is correct
12 Correct 53 ms 25684 KB Output is correct
13 Correct 57 ms 25684 KB Output is correct
14 Correct 56 ms 25680 KB Output is correct
15 Correct 58 ms 25684 KB Output is correct
16 Correct 63 ms 25704 KB Output is correct
17 Correct 55 ms 25748 KB Output is correct
18 Correct 51 ms 24656 KB Output is correct
19 Correct 58 ms 24652 KB Output is correct
20 Correct 59 ms 25532 KB Output is correct
21 Correct 65 ms 25680 KB Output is correct
22 Correct 61 ms 25680 KB Output is correct
23 Correct 62 ms 25688 KB Output is correct
24 Correct 63 ms 25936 KB Output is correct
25 Correct 73 ms 25936 KB Output is correct
26 Correct 62 ms 25876 KB Output is correct
27 Correct 63 ms 25940 KB Output is correct
28 Correct 81 ms 24656 KB Output is correct
29 Correct 82 ms 24656 KB Output is correct
30 Correct 79 ms 24660 KB Output is correct
31 Correct 12 ms 23896 KB Output is correct
32 Correct 11 ms 23900 KB Output is correct
33 Correct 52 ms 24624 KB Output is correct
34 Correct 53 ms 25680 KB Output is correct
35 Correct 58 ms 25860 KB Output is correct
36 Correct 61 ms 25684 KB Output is correct
37 Correct 63 ms 25684 KB Output is correct
38 Correct 58 ms 25684 KB Output is correct
39 Correct 55 ms 25764 KB Output is correct
40 Correct 52 ms 24656 KB Output is correct
41 Correct 58 ms 24720 KB Output is correct
42 Correct 60 ms 25424 KB Output is correct
43 Correct 70 ms 25900 KB Output is correct
44 Correct 64 ms 25684 KB Output is correct
45 Correct 61 ms 25680 KB Output is correct
46 Correct 62 ms 25744 KB Output is correct
47 Correct 66 ms 25940 KB Output is correct
48 Correct 58 ms 25936 KB Output is correct
49 Correct 57 ms 25940 KB Output is correct
50 Correct 75 ms 25936 KB Output is correct
51 Correct 59 ms 24912 KB Output is correct
52 Correct 78 ms 26060 KB Output is correct
53 Correct 68 ms 25692 KB Output is correct
54 Correct 72 ms 25948 KB Output is correct
55 Correct 79 ms 25940 KB Output is correct
56 Correct 102 ms 26964 KB Output is correct
57 Correct 57 ms 25932 KB Output is correct
58 Correct 80 ms 26704 KB Output is correct
59 Correct 64 ms 25720 KB Output is correct
60 Correct 79 ms 24660 KB Output is correct
61 Correct 78 ms 24656 KB Output is correct
62 Correct 81 ms 24552 KB Output is correct
63 Correct 12 ms 23900 KB Output is correct
64 Correct 13 ms 23900 KB Output is correct
65 Correct 53 ms 24660 KB Output is correct
66 Correct 54 ms 25676 KB Output is correct
67 Correct 59 ms 25680 KB Output is correct
68 Correct 57 ms 25676 KB Output is correct
69 Correct 67 ms 25680 KB Output is correct
70 Correct 57 ms 25712 KB Output is correct
71 Correct 55 ms 25688 KB Output is correct
72 Correct 51 ms 24660 KB Output is correct
73 Correct 60 ms 24720 KB Output is correct
74 Correct 86 ms 25424 KB Output is correct
75 Correct 70 ms 25888 KB Output is correct
76 Correct 69 ms 25916 KB Output is correct
77 Correct 64 ms 25804 KB Output is correct
78 Correct 65 ms 25936 KB Output is correct
79 Correct 68 ms 25940 KB Output is correct
80 Correct 56 ms 25832 KB Output is correct
81 Correct 57 ms 25940 KB Output is correct
82 Correct 12 ms 23900 KB Output is correct
83 Correct 60 ms 25892 KB Output is correct
84 Correct 80 ms 26776 KB Output is correct
85 Correct 76 ms 25960 KB Output is correct
86 Correct 62 ms 24916 KB Output is correct
87 Correct 85 ms 26220 KB Output is correct
88 Correct 85 ms 25936 KB Output is correct
89 Correct 84 ms 25684 KB Output is correct
90 Correct 85 ms 25744 KB Output is correct
91 Correct 83 ms 25684 KB Output is correct
92 Correct 83 ms 25936 KB Output is correct
93 Correct 81 ms 24968 KB Output is correct
94 Correct 74 ms 25988 KB Output is correct
95 Correct 74 ms 25940 KB Output is correct
96 Correct 88 ms 25816 KB Output is correct
97 Correct 99 ms 26196 KB Output is correct
98 Correct 162 ms 26960 KB Output is correct
99 Correct 867 ms 24780 KB Output is correct
100 Correct 101 ms 26452 KB Output is correct
101 Correct 67 ms 25424 KB Output is correct
102 Correct 12 ms 23896 KB Output is correct
103 Correct 52 ms 24660 KB Output is correct
104 Correct 53 ms 25684 KB Output is correct
105 Correct 57 ms 25940 KB Output is correct
106 Correct 57 ms 25684 KB Output is correct
107 Correct 60 ms 25840 KB Output is correct
108 Correct 58 ms 25684 KB Output is correct
109 Correct 55 ms 25880 KB Output is correct
110 Correct 59 ms 24912 KB Output is correct
111 Correct 76 ms 25888 KB Output is correct
112 Correct 2281 ms 26988 KB Output is correct
113 Execution timed out 4048 ms 27056 KB Time limit exceeded
114 Halted 0 ms 0 KB -