답안 #773204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773204 2023-07-04T16:38:18 Z rainboy Alternating Heights (CCO22_day1problem1) C
25 / 25
427 ms 13844 KB
#include <stdio.h>
#include <stdlib.h>

#define N	3000
#define M	3000

int *ej[N], eo[N], fo[N], n;

void append(int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
	ej[i][o] = j;
}

int ii[M], m;

int check(int l, int r) {
	static int qu[N];
	int cnt, h, i, j, o;

	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]), eo[i] = 0, fo[i] = 0;
	for (h = l; h < r; h++)
		if (h % 2 == 0)
			append(ii[h], ii[h + 1]), fo[ii[h + 1]]++;
		else
			append(ii[h + 1], ii[h]), fo[ii[h]]++;
	cnt = 0;
	for (i = 0; i < n; i++)
		if (fo[i] == 0)
			qu[cnt++] = i;
	for (h = 0; h < cnt; h++) {
		i = qu[h];
		for (o = eo[i]; o--; ) {
			j = ej[i][o];
			if (--fo[j] == 0)
				qu[cnt++] = j;
		}
	}
	for (i = 0; i < n; i++)
		free(ej[i]);
	return cnt == n;
}

int main() {
	static int rr[M];
	int q, h, l, r;

	scanf("%d%d%d", &m, &n, &q);
	for (h = 0; h < m; h++)
		scanf("%d", &ii[h]), ii[h]--;
	for (l = 0, r = 0; l < m; l++) {
		while (r < m && check(l, r))
			r++;
		rr[l] = r;
	}
	while (q--) {
		scanf("%d%d", &l, &r), l--, r--;
		printf(r < rr[l] ? "YES\n" : "NO\n");
	}
	return 0;
}

Compilation message

Main.c: In function 'append':
Main.c:12:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   12 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Main.c: In function 'main':
Main.c:51:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%d%d%d", &m, &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:53:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   scanf("%d", &ii[h]), ii[h]--;
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:60:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d%d", &l, &r), l--, r--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 12592 KB Output is correct
2 Correct 155 ms 12580 KB Output is correct
3 Correct 182 ms 12780 KB Output is correct
4 Correct 135 ms 7092 KB Output is correct
5 Correct 142 ms 9232 KB Output is correct
6 Correct 152 ms 12596 KB Output is correct
7 Correct 152 ms 12636 KB Output is correct
8 Correct 172 ms 12796 KB Output is correct
9 Correct 159 ms 12716 KB Output is correct
10 Correct 182 ms 13176 KB Output is correct
11 Correct 181 ms 13608 KB Output is correct
12 Correct 211 ms 12928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 190 ms 10956 KB Output is correct
2 Correct 144 ms 10956 KB Output is correct
3 Correct 171 ms 10856 KB Output is correct
4 Correct 135 ms 8108 KB Output is correct
5 Correct 146 ms 9264 KB Output is correct
6 Correct 147 ms 10908 KB Output is correct
7 Correct 155 ms 10988 KB Output is correct
8 Correct 160 ms 10988 KB Output is correct
9 Correct 153 ms 11248 KB Output is correct
10 Correct 147 ms 11892 KB Output is correct
11 Correct 149 ms 11864 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 263 ms 468 KB Output is correct
3 Correct 262 ms 472 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 158 ms 428 KB Output is correct
8 Correct 215 ms 592 KB Output is correct
9 Correct 267 ms 468 KB Output is correct
10 Correct 127 ms 340 KB Output is correct
11 Correct 167 ms 472 KB Output is correct
12 Correct 103 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 12592 KB Output is correct
2 Correct 155 ms 12580 KB Output is correct
3 Correct 182 ms 12780 KB Output is correct
4 Correct 135 ms 7092 KB Output is correct
5 Correct 142 ms 9232 KB Output is correct
6 Correct 152 ms 12596 KB Output is correct
7 Correct 152 ms 12636 KB Output is correct
8 Correct 172 ms 12796 KB Output is correct
9 Correct 159 ms 12716 KB Output is correct
10 Correct 182 ms 13176 KB Output is correct
11 Correct 181 ms 13608 KB Output is correct
12 Correct 211 ms 12928 KB Output is correct
13 Correct 190 ms 10956 KB Output is correct
14 Correct 144 ms 10956 KB Output is correct
15 Correct 171 ms 10856 KB Output is correct
16 Correct 135 ms 8108 KB Output is correct
17 Correct 146 ms 9264 KB Output is correct
18 Correct 147 ms 10908 KB Output is correct
19 Correct 155 ms 10988 KB Output is correct
20 Correct 160 ms 10988 KB Output is correct
21 Correct 153 ms 11248 KB Output is correct
22 Correct 147 ms 11892 KB Output is correct
23 Correct 149 ms 11864 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 263 ms 468 KB Output is correct
27 Correct 262 ms 472 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 158 ms 428 KB Output is correct
32 Correct 215 ms 592 KB Output is correct
33 Correct 267 ms 468 KB Output is correct
34 Correct 127 ms 340 KB Output is correct
35 Correct 167 ms 472 KB Output is correct
36 Correct 103 ms 400 KB Output is correct
37 Correct 394 ms 13452 KB Output is correct
38 Correct 427 ms 13256 KB Output is correct
39 Correct 153 ms 12596 KB Output is correct
40 Correct 138 ms 8144 KB Output is correct
41 Correct 159 ms 9672 KB Output is correct
42 Correct 356 ms 13332 KB Output is correct
43 Correct 312 ms 13564 KB Output is correct
44 Correct 243 ms 13228 KB Output is correct
45 Correct 310 ms 13720 KB Output is correct
46 Correct 280 ms 13772 KB Output is correct
47 Correct 310 ms 13844 KB Output is correct