답안 #917336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
917336 2024-01-27T21:26:47 Z rainboy 줄서기 (KOI17_line) C++
100 / 100
154 ms 21836 KB
#include <stdio.h>
#include <stdlib.h>

#define N	100000

int *ei[N], eo[N];

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

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

int main() {
	static int aa[N];
	int n, m, h, i, j, o;

	scanf("%d%d", &n, &m);
	for (j = 0; j < n; j++)
		ei[j] = (int *) malloc(2 * sizeof *ei[j]);
	for (h = 0; h < m; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		append(j, i);
	}
	for (j = 0; j < n; j++) {
		for (o = eo[j]; o--; ) {
			i = ei[j][o];
			if (aa[i]++ < j - eo[j]) {
				printf("-1\n");
				return 0;
			}
		}
		aa[j] = j - eo[j];
	}
	for (i = 0; i < n; i++)
		printf("%d ", aa[i] + 1);
	printf("\n");
	return 0;
}

Compilation message

line.cpp: In function 'void append(int, int)':
line.cpp:11:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   11 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
line.cpp: In function 'int main()':
line.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
line.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%d%d", &i, &j), i--, j--;
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 440 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 440 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 6 ms 936 KB Output is correct
24 Correct 14 ms 1628 KB Output is correct
25 Correct 57 ms 6696 KB Output is correct
26 Correct 15 ms 1884 KB Output is correct
27 Correct 44 ms 5276 KB Output is correct
28 Correct 46 ms 5584 KB Output is correct
29 Correct 79 ms 10196 KB Output is correct
30 Correct 119 ms 14488 KB Output is correct
31 Correct 56 ms 6696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 440 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 6 ms 936 KB Output is correct
24 Correct 14 ms 1628 KB Output is correct
25 Correct 57 ms 6696 KB Output is correct
26 Correct 15 ms 1884 KB Output is correct
27 Correct 44 ms 5276 KB Output is correct
28 Correct 46 ms 5584 KB Output is correct
29 Correct 79 ms 10196 KB Output is correct
30 Correct 119 ms 14488 KB Output is correct
31 Correct 56 ms 6696 KB Output is correct
32 Correct 50 ms 8152 KB Output is correct
33 Correct 64 ms 10120 KB Output is correct
34 Correct 101 ms 15608 KB Output is correct
35 Correct 97 ms 14392 KB Output is correct
36 Correct 100 ms 16008 KB Output is correct
37 Correct 126 ms 19400 KB Output is correct
38 Correct 132 ms 19696 KB Output is correct
39 Correct 154 ms 21836 KB Output is correct
40 Correct 144 ms 21588 KB Output is correct