답안 #922618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922618 2024-02-05T20:06:20 Z rainboy Travels (LMIO17_keliones) C
100 / 100
64 ms 23888 KB
#include <stdio.h>
#include <stdlib.h>

#define N	200000
#define MD	1000000007

void append(int **ej, int *eo, 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 main() {
	static int ww[N], *ej[N], eo[N], *fi[N], fo[N], dp[N], dq[N];
	int n, m, h, i, j, o, sum, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%d", &ww[i]);
	for (i = 0; i < n; i++) {
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
		fi[i] = (int *) malloc(2 * sizeof *fi[i]);
	}
	for (h = 0; h < m; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		append(ej, eo, i, j), append(fi, fo, j, i);
	}
	sum = 0;
	for (j = 0; j < n; j++) {
		dp[j] = (sum + 1) % MD;
		for (o = fo[j]; o--; ) {
			i = fi[j][o];
			dp[j] = (dp[j] - dp[i] + MD) % MD;
		}
		sum = (sum + dp[j]) % MD;
	}
	sum = 0;
	for (i = n - 1; i >= 0; i--) {
		dq[i] = (sum + 1) % MD;
		for (o = eo[i]; o--; ) {
			j = ej[i][o];
			dq[i] = (dq[i] - dq[j] + MD) % MD;
		}
		sum = (sum + dq[i]) % MD;
	}
	ans = 0;
	for (i = 0; i < n; i++)
		ans = (ans + ww[i] * (((long long) dp[i] * dq[i] - 1 + MD) % MD)) % MD;
	printf("%d\n", ans);
	return 0;
}

Compilation message

keliones.c: In function 'append':
keliones.c:10:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   10 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
keliones.c: In function 'main':
keliones.c:19:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
keliones.c:21:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d", &ww[i]);
      |   ^~~~~~~~~~~~~~~~~~~
keliones.c:27:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 2 ms 4528 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 2 ms 4528 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 12 ms 6236 KB Output is correct
14 Correct 13 ms 6420 KB Output is correct
15 Correct 10 ms 5960 KB Output is correct
16 Correct 4 ms 4956 KB Output is correct
17 Correct 11 ms 5980 KB Output is correct
18 Correct 7 ms 5464 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4532 KB Output is correct
23 Correct 1 ms 4536 KB Output is correct
24 Correct 1 ms 4532 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 2 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 6236 KB Output is correct
2 Correct 13 ms 6420 KB Output is correct
3 Correct 10 ms 5960 KB Output is correct
4 Correct 4 ms 4956 KB Output is correct
5 Correct 11 ms 5980 KB Output is correct
6 Correct 7 ms 5464 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4532 KB Output is correct
11 Correct 1 ms 4536 KB Output is correct
12 Correct 1 ms 4532 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4528 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 4696 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 17 ms 6748 KB Output is correct
29 Correct 4 ms 5212 KB Output is correct
30 Correct 9 ms 5980 KB Output is correct
31 Correct 4 ms 5212 KB Output is correct
32 Correct 1 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 13 ms 6408 KB Output is correct
35 Correct 16 ms 7004 KB Output is correct
36 Correct 17 ms 7008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 6236 KB Output is correct
2 Correct 13 ms 6420 KB Output is correct
3 Correct 10 ms 5960 KB Output is correct
4 Correct 4 ms 4956 KB Output is correct
5 Correct 11 ms 5980 KB Output is correct
6 Correct 7 ms 5464 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4532 KB Output is correct
11 Correct 1 ms 4536 KB Output is correct
12 Correct 1 ms 4532 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 17 ms 6748 KB Output is correct
17 Correct 4 ms 5212 KB Output is correct
18 Correct 9 ms 5980 KB Output is correct
19 Correct 4 ms 5212 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 13 ms 6408 KB Output is correct
23 Correct 16 ms 7004 KB Output is correct
24 Correct 17 ms 7008 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 2 ms 4528 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4440 KB Output is correct
34 Correct 1 ms 4696 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 44 ms 21588 KB Output is correct
38 Correct 38 ms 21328 KB Output is correct
39 Correct 42 ms 21684 KB Output is correct
40 Correct 64 ms 22612 KB Output is correct
41 Correct 33 ms 21376 KB Output is correct
42 Correct 60 ms 22276 KB Output is correct
43 Correct 29 ms 21328 KB Output is correct
44 Correct 59 ms 23888 KB Output is correct
45 Correct 59 ms 23868 KB Output is correct