Submission #545930

# Submission time Handle Problem Language Result Execution time Memory
545930 2022-04-05T16:12:13 Z rainboy Amusement Park (CEOI19_amusementpark) C
100 / 100
300 ms 59892 KB
/* https://codeforces.com/blog/entry/68748?#comment-530893 (Paulliant) */
#include <stdio.h>

#define N	18
#define MD	998244353
#define MD2	996491788296388609LL
#define V2	499122177

void sub(int *aa, int n) {
	int i, b;

	for (i = 0; i < n; i++)
		for (b = 0; b < 1 << n; b++)
			if ((b & 1 << i) != 0 && (aa[b] += aa[b ^ 1 << i]) >= MD)
				aa[b] -= MD;
}

int main() {
	static int adj[N], cnt[1 << N], dp[N + 1][1 << N];
	static long long dq[N + 1][1 << N];
	int n, m, h, i, j, k, l, b, c;
	long long ans;

	scanf("%d%d", &n, &m);
	for (h = 0; h < m; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		adj[i] |= 1 << j, adj[j] |= 1 << i;
	}
	for (b = 1; b < 1 << n; b++)
		cnt[b] = cnt[b & b - 1] + 1;
	for (b = 1; b < 1 << n; b++) {
		c = 0;
		for (i = 0; i < n; i++)
			if ((b & 1 << i) != 0)
				c |= adj[i];
		if ((b & c) != 0)
			continue;
		dp[cnt[b]][b] = cnt[b] % 2 == 0 ? MD - 1 : 1;
	}
	for (k = 0; k <= n; k++)
		sub(dp[k], n);
	for (b = 0; b < 1 << n; b++)
		dq[0][b] = 1;
	for (k = 0; k < n; k++) {
		for (b = 0; b < 1 << n; b++)
			dq[k][b] %= MD;
		for (l = 1; k + l <= n; l++)
			for (b = 0; b < 1 << n; b++)
				if ((dq[k + l][b] += dq[k][b] * dp[l][b]) >= MD2)
					dq[k + l][b] -= MD2;
	}
	ans = 0;
	for (b = 0; b < 1 << n; b++)
		ans += dq[k][b] % MD * (cnt[(1 << n) - 1 ^ b] % 2 == 0 ? 1 : -1);
	ans %= MD;
	if (ans < 0)
		ans += MD;
	ans = ans * m % MD * V2 % MD;
	printf("%lld\n", ans);
	return 0;
}

Compilation message

amusementpark.c: In function 'main':
amusementpark.c:30:22: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   30 |   cnt[b] = cnt[b & b - 1] + 1;
      |                    ~~^~~
amusementpark.c:54:40: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   54 |   ans += dq[k][b] % MD * (cnt[(1 << n) - 1 ^ b] % 2 == 0 ? 1 : -1);
      |                               ~~~~~~~~~^~~
amusementpark.c:24:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
amusementpark.c:26:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 292 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 292 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 420 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 416 KB Output is correct
39 Correct 1 ms 416 KB Output is correct
40 Correct 1 ms 420 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 416 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 420 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 416 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 420 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 292 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 420 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 416 KB Output is correct
39 Correct 1 ms 416 KB Output is correct
40 Correct 1 ms 420 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 416 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 420 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 416 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 420 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 544 KB Output is correct
65 Correct 15 ms 3328 KB Output is correct
66 Correct 15 ms 3368 KB Output is correct
67 Correct 11 ms 3368 KB Output is correct
68 Correct 11 ms 3412 KB Output is correct
69 Correct 12 ms 3364 KB Output is correct
70 Correct 14 ms 3384 KB Output is correct
71 Correct 10 ms 3388 KB Output is correct
72 Correct 11 ms 3364 KB Output is correct
73 Correct 10 ms 3448 KB Output is correct
74 Correct 10 ms 3412 KB Output is correct
75 Correct 10 ms 3404 KB Output is correct
76 Correct 15 ms 3412 KB Output is correct
77 Correct 22 ms 6772 KB Output is correct
78 Correct 23 ms 6700 KB Output is correct
79 Correct 22 ms 6740 KB Output is correct
80 Correct 23 ms 6792 KB Output is correct
81 Correct 22 ms 6740 KB Output is correct
82 Correct 29 ms 6740 KB Output is correct
83 Correct 23 ms 6792 KB Output is correct
84 Correct 24 ms 6696 KB Output is correct
85 Correct 33 ms 6740 KB Output is correct
86 Correct 33 ms 6740 KB Output is correct
87 Correct 33 ms 6772 KB Output is correct
88 Correct 22 ms 6656 KB Output is correct
89 Correct 21 ms 6728 KB Output is correct
90 Correct 22 ms 6740 KB Output is correct
91 Correct 22 ms 6692 KB Output is correct
92 Correct 23 ms 6772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 292 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 420 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 416 KB Output is correct
39 Correct 1 ms 416 KB Output is correct
40 Correct 1 ms 420 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 416 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 420 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 416 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 420 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 544 KB Output is correct
65 Correct 15 ms 3328 KB Output is correct
66 Correct 15 ms 3368 KB Output is correct
67 Correct 11 ms 3368 KB Output is correct
68 Correct 11 ms 3412 KB Output is correct
69 Correct 12 ms 3364 KB Output is correct
70 Correct 14 ms 3384 KB Output is correct
71 Correct 10 ms 3388 KB Output is correct
72 Correct 11 ms 3364 KB Output is correct
73 Correct 10 ms 3448 KB Output is correct
74 Correct 10 ms 3412 KB Output is correct
75 Correct 10 ms 3404 KB Output is correct
76 Correct 15 ms 3412 KB Output is correct
77 Correct 22 ms 6772 KB Output is correct
78 Correct 23 ms 6700 KB Output is correct
79 Correct 22 ms 6740 KB Output is correct
80 Correct 23 ms 6792 KB Output is correct
81 Correct 22 ms 6740 KB Output is correct
82 Correct 29 ms 6740 KB Output is correct
83 Correct 23 ms 6792 KB Output is correct
84 Correct 24 ms 6696 KB Output is correct
85 Correct 33 ms 6740 KB Output is correct
86 Correct 33 ms 6740 KB Output is correct
87 Correct 33 ms 6772 KB Output is correct
88 Correct 22 ms 6656 KB Output is correct
89 Correct 21 ms 6728 KB Output is correct
90 Correct 22 ms 6740 KB Output is correct
91 Correct 22 ms 6692 KB Output is correct
92 Correct 23 ms 6772 KB Output is correct
93 Correct 236 ms 59772 KB Output is correct
94 Correct 255 ms 59772 KB Output is correct
95 Correct 285 ms 59892 KB Output is correct
96 Correct 255 ms 59884 KB Output is correct
97 Correct 282 ms 59776 KB Output is correct
98 Correct 269 ms 59704 KB Output is correct
99 Correct 50 ms 13824 KB Output is correct
100 Correct 51 ms 13756 KB Output is correct
101 Correct 77 ms 13800 KB Output is correct
102 Correct 52 ms 13776 KB Output is correct
103 Correct 122 ms 28620 KB Output is correct
104 Correct 115 ms 28668 KB Output is correct
105 Correct 127 ms 28688 KB Output is correct
106 Correct 116 ms 28596 KB Output is correct
107 Correct 245 ms 59772 KB Output is correct
108 Correct 253 ms 59728 KB Output is correct
109 Correct 244 ms 59712 KB Output is correct
110 Correct 271 ms 59720 KB Output is correct
111 Correct 50 ms 13708 KB Output is correct
112 Correct 59 ms 13812 KB Output is correct
113 Correct 68 ms 13824 KB Output is correct
114 Correct 49 ms 13804 KB Output is correct
115 Correct 49 ms 13824 KB Output is correct
116 Correct 52 ms 13824 KB Output is correct
117 Correct 52 ms 13832 KB Output is correct
118 Correct 53 ms 13728 KB Output is correct
119 Correct 49 ms 13808 KB Output is correct
120 Correct 49 ms 13780 KB Output is correct
121 Correct 50 ms 13824 KB Output is correct
122 Correct 108 ms 28632 KB Output is correct
123 Correct 110 ms 28620 KB Output is correct
124 Correct 108 ms 28672 KB Output is correct
125 Correct 109 ms 28628 KB Output is correct
126 Correct 111 ms 28684 KB Output is correct
127 Correct 109 ms 28684 KB Output is correct
128 Correct 133 ms 28640 KB Output is correct
129 Correct 129 ms 28680 KB Output is correct
130 Correct 111 ms 28684 KB Output is correct
131 Correct 112 ms 28680 KB Output is correct
132 Correct 115 ms 28600 KB Output is correct
133 Correct 112 ms 28596 KB Output is correct
134 Correct 108 ms 28620 KB Output is correct
135 Correct 127 ms 28616 KB Output is correct
136 Correct 118 ms 28608 KB Output is correct
137 Correct 112 ms 28592 KB Output is correct
138 Correct 107 ms 28688 KB Output is correct
139 Correct 106 ms 28596 KB Output is correct
140 Correct 109 ms 28664 KB Output is correct
141 Correct 124 ms 28684 KB Output is correct
142 Correct 232 ms 59772 KB Output is correct
143 Correct 260 ms 59696 KB Output is correct
144 Correct 258 ms 59692 KB Output is correct
145 Correct 245 ms 59724 KB Output is correct
146 Correct 268 ms 59800 KB Output is correct
147 Correct 242 ms 59772 KB Output is correct
148 Correct 246 ms 59672 KB Output is correct
149 Correct 278 ms 59768 KB Output is correct
150 Correct 249 ms 59708 KB Output is correct
151 Correct 300 ms 59768 KB Output is correct
152 Correct 264 ms 59704 KB Output is correct
153 Correct 285 ms 59768 KB Output is correct
154 Correct 264 ms 59772 KB Output is correct
155 Correct 281 ms 59700 KB Output is correct
156 Correct 249 ms 59776 KB Output is correct
157 Correct 275 ms 59716 KB Output is correct
158 Correct 289 ms 59652 KB Output is correct
159 Correct 260 ms 59652 KB Output is correct
160 Correct 246 ms 59680 KB Output is correct
161 Correct 260 ms 59728 KB Output is correct
162 Correct 279 ms 59676 KB Output is correct
163 Correct 251 ms 59776 KB Output is correct
164 Correct 259 ms 59700 KB Output is correct
165 Correct 249 ms 59772 KB Output is correct
166 Correct 260 ms 59760 KB Output is correct
167 Correct 262 ms 59700 KB Output is correct