# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
582553 | 2022-06-24T05:26:30 Z | 박상훈(#8369) | Amusement Park (CEOI19_amusementpark) | C++17 | 2122 ms | 3416 KB |
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int MOD = 998244353; int adj[20][20], dp1[(1<<18)], dp2[(1<<18)], p[(1<<18)], cnt[18]; int main(){ int n, m; scanf("%d %d", &n, &m); for (int i=1;i<=m;i++){ int x, y; scanf("%d %d", &x, &y); --x, --y; adj[x][y] = 1; adj[y][x] = -1; } for (int z=0;z<(1<<n);z++){ p[z] = 1; for (int i=0;i<n;i++) if (z&(1<<i)){ for (int j=i+1;j<n;j++) if (z&(1<<j)){ if (adj[i][j]) p[z] = 0; } } } for (int z=0;z<(1<<n);z++) if (__builtin_popcount(z)<2) dp2[z] = 1; for (int z=0;z<(1<<n);z++) if (__builtin_popcount(z)>=2){ memset(cnt, 0, sizeof(cnt)); for (int i=0;i<n;i++) if (z&(1<<i)){ for (int j=0;j<n;j++) if (z&(1<<j) && adj[i][j]==-1) cnt[i]++; } for (int z2=z;z2;z2=(z2-1)&z) if (p[z2]){ ll cst = 0; if (n<=15) {for (int i=0;i<n;i++) if (z2&(1<<i)) cst += cnt[i];} if (__builtin_popcount(z2)&1){ dp1[z] += (cst * dp2[z^z2] + dp1[z^z2]) % MOD; dp2[z] += dp2[z^z2]; if (dp1[z]>=MOD) dp1[z] -= MOD; if (dp2[z]>=MOD) dp2[z] -= MOD; } else{ dp1[z] -= (cst * dp2[z^z2] + dp1[z^z2]) % MOD; dp2[z] -= dp2[z^z2]; if (dp1[z]<0) dp1[z] += MOD; if (dp2[z]<0) dp2[z] += MOD; } } } printf("%d\n", dp1[(1<<n)-1]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 1 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 340 KB | Output is correct |
40 | Correct | 1 ms | 212 KB | Output is correct |
41 | Correct | 1 ms | 212 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 1 ms | 212 KB | Output is correct |
44 | Correct | 1 ms | 212 KB | Output is correct |
45 | Correct | 1 ms | 212 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 1 ms | 212 KB | Output is correct |
49 | Correct | 1 ms | 212 KB | Output is correct |
50 | Correct | 1 ms | 212 KB | Output is correct |
51 | Correct | 1 ms | 212 KB | Output is correct |
52 | Correct | 2 ms | 212 KB | Output is correct |
53 | Correct | 2 ms | 340 KB | Output is correct |
54 | Correct | 2 ms | 212 KB | Output is correct |
55 | Correct | 2 ms | 212 KB | Output is correct |
56 | Correct | 1 ms | 212 KB | Output is correct |
57 | Correct | 1 ms | 212 KB | Output is correct |
58 | Correct | 1 ms | 212 KB | Output is correct |
59 | Correct | 2 ms | 212 KB | Output is correct |
60 | Correct | 1 ms | 212 KB | Output is correct |
61 | Correct | 2 ms | 332 KB | Output is correct |
62 | Correct | 2 ms | 340 KB | Output is correct |
63 | Correct | 2 ms | 320 KB | Output is correct |
64 | Correct | 2 ms | 324 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 1 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 340 KB | Output is correct |
40 | Correct | 1 ms | 212 KB | Output is correct |
41 | Correct | 1 ms | 212 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 1 ms | 212 KB | Output is correct |
44 | Correct | 1 ms | 212 KB | Output is correct |
45 | Correct | 1 ms | 212 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 1 ms | 212 KB | Output is correct |
49 | Correct | 1 ms | 212 KB | Output is correct |
50 | Correct | 1 ms | 212 KB | Output is correct |
51 | Correct | 1 ms | 212 KB | Output is correct |
52 | Correct | 2 ms | 212 KB | Output is correct |
53 | Correct | 2 ms | 340 KB | Output is correct |
54 | Correct | 2 ms | 212 KB | Output is correct |
55 | Correct | 2 ms | 212 KB | Output is correct |
56 | Correct | 1 ms | 212 KB | Output is correct |
57 | Correct | 1 ms | 212 KB | Output is correct |
58 | Correct | 1 ms | 212 KB | Output is correct |
59 | Correct | 2 ms | 212 KB | Output is correct |
60 | Correct | 1 ms | 212 KB | Output is correct |
61 | Correct | 2 ms | 332 KB | Output is correct |
62 | Correct | 2 ms | 340 KB | Output is correct |
63 | Correct | 2 ms | 320 KB | Output is correct |
64 | Correct | 2 ms | 324 KB | Output is correct |
65 | Correct | 37 ms | 460 KB | Output is correct |
66 | Correct | 33 ms | 456 KB | Output is correct |
67 | Correct | 35 ms | 468 KB | Output is correct |
68 | Correct | 33 ms | 468 KB | Output is correct |
69 | Correct | 180 ms | 424 KB | Output is correct |
70 | Correct | 122 ms | 464 KB | Output is correct |
71 | Correct | 115 ms | 416 KB | Output is correct |
72 | Correct | 106 ms | 420 KB | Output is correct |
73 | Correct | 78 ms | 448 KB | Output is correct |
74 | Correct | 77 ms | 576 KB | Output is correct |
75 | Correct | 80 ms | 416 KB | Output is correct |
76 | Correct | 72 ms | 444 KB | Output is correct |
77 | Correct | 145 ms | 652 KB | Output is correct |
78 | Correct | 107 ms | 684 KB | Output is correct |
79 | Correct | 92 ms | 580 KB | Output is correct |
80 | Correct | 79 ms | 652 KB | Output is correct |
81 | Correct | 73 ms | 688 KB | Output is correct |
82 | Correct | 65 ms | 668 KB | Output is correct |
83 | Correct | 62 ms | 588 KB | Output is correct |
84 | Correct | 56 ms | 588 KB | Output is correct |
85 | Correct | 543 ms | 808 KB | Output is correct |
86 | Correct | 341 ms | 624 KB | Output is correct |
87 | Correct | 369 ms | 772 KB | Output is correct |
88 | Correct | 327 ms | 620 KB | Output is correct |
89 | Correct | 236 ms | 656 KB | Output is correct |
90 | Correct | 233 ms | 668 KB | Output is correct |
91 | Correct | 240 ms | 684 KB | Output is correct |
92 | Correct | 228 ms | 764 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 1 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 340 KB | Output is correct |
40 | Correct | 1 ms | 212 KB | Output is correct |
41 | Correct | 1 ms | 212 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 1 ms | 212 KB | Output is correct |
44 | Correct | 1 ms | 212 KB | Output is correct |
45 | Correct | 1 ms | 212 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 1 ms | 212 KB | Output is correct |
49 | Correct | 1 ms | 212 KB | Output is correct |
50 | Correct | 1 ms | 212 KB | Output is correct |
51 | Correct | 1 ms | 212 KB | Output is correct |
52 | Correct | 2 ms | 212 KB | Output is correct |
53 | Correct | 2 ms | 340 KB | Output is correct |
54 | Correct | 2 ms | 212 KB | Output is correct |
55 | Correct | 2 ms | 212 KB | Output is correct |
56 | Correct | 1 ms | 212 KB | Output is correct |
57 | Correct | 1 ms | 212 KB | Output is correct |
58 | Correct | 1 ms | 212 KB | Output is correct |
59 | Correct | 2 ms | 212 KB | Output is correct |
60 | Correct | 1 ms | 212 KB | Output is correct |
61 | Correct | 2 ms | 332 KB | Output is correct |
62 | Correct | 2 ms | 340 KB | Output is correct |
63 | Correct | 2 ms | 320 KB | Output is correct |
64 | Correct | 2 ms | 324 KB | Output is correct |
65 | Correct | 37 ms | 460 KB | Output is correct |
66 | Correct | 33 ms | 456 KB | Output is correct |
67 | Correct | 35 ms | 468 KB | Output is correct |
68 | Correct | 33 ms | 468 KB | Output is correct |
69 | Correct | 180 ms | 424 KB | Output is correct |
70 | Correct | 122 ms | 464 KB | Output is correct |
71 | Correct | 115 ms | 416 KB | Output is correct |
72 | Correct | 106 ms | 420 KB | Output is correct |
73 | Correct | 78 ms | 448 KB | Output is correct |
74 | Correct | 77 ms | 576 KB | Output is correct |
75 | Correct | 80 ms | 416 KB | Output is correct |
76 | Correct | 72 ms | 444 KB | Output is correct |
77 | Correct | 145 ms | 652 KB | Output is correct |
78 | Correct | 107 ms | 684 KB | Output is correct |
79 | Correct | 92 ms | 580 KB | Output is correct |
80 | Correct | 79 ms | 652 KB | Output is correct |
81 | Correct | 73 ms | 688 KB | Output is correct |
82 | Correct | 65 ms | 668 KB | Output is correct |
83 | Correct | 62 ms | 588 KB | Output is correct |
84 | Correct | 56 ms | 588 KB | Output is correct |
85 | Correct | 543 ms | 808 KB | Output is correct |
86 | Correct | 341 ms | 624 KB | Output is correct |
87 | Correct | 369 ms | 772 KB | Output is correct |
88 | Correct | 327 ms | 620 KB | Output is correct |
89 | Correct | 236 ms | 656 KB | Output is correct |
90 | Correct | 233 ms | 668 KB | Output is correct |
91 | Correct | 240 ms | 684 KB | Output is correct |
92 | Correct | 228 ms | 764 KB | Output is correct |
93 | Incorrect | 2122 ms | 3416 KB | Output isn't correct |
94 | Halted | 0 ms | 0 KB | - |