# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
582558 | 2022-06-24T05:32:42 Z | 박상훈(#8369) | Amusement Park (CEOI19_amusementpark) | C++17 | 3000 ms | 5508 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]; ll cst[(1<<18)]; int main(){ //printf("%d\n", __builtin_ctz(10)); 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)); cst[z] = 0; 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]++, cst[z]++; } for (int z2=(z-1)&z;z2;z2=(z2-1)&z){ cst[z2] = cst[z2 | (1<<(__builtin_ctz(z^z2)))] - cnt[__builtin_ctz(z^z2)]; } for (int z2=z;z2;z2=(z2-1)&z) if (p[z2]){ //ll cst = 0; //for (int i=0;i<n;i++) if (z2&(1<<i)) cst += cnt[i]; if (__builtin_popcount(z2)&1){ dp1[z] += (cst[z2] * 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[z2] * 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 | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 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 | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | 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 | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 0 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 | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 0 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 | 212 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 | 340 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 | 1 ms | 340 KB | Output is correct |
53 | Correct | 1 ms | 340 KB | Output is correct |
54 | Correct | 1 ms | 340 KB | Output is correct |
55 | Correct | 1 ms | 340 KB | Output is correct |
56 | Correct | 1 ms | 340 KB | Output is correct |
57 | Correct | 1 ms | 340 KB | Output is correct |
58 | Correct | 1 ms | 340 KB | Output is correct |
59 | Correct | 1 ms | 340 KB | Output is correct |
60 | Correct | 1 ms | 340 KB | Output is correct |
61 | Correct | 1 ms | 340 KB | Output is correct |
62 | Correct | 1 ms | 340 KB | Output is correct |
63 | Correct | 1 ms | 340 KB | Output is correct |
64 | Correct | 1 ms | 340 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 | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 0 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 | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 0 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 | 212 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 | 340 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 | 1 ms | 340 KB | Output is correct |
53 | Correct | 1 ms | 340 KB | Output is correct |
54 | Correct | 1 ms | 340 KB | Output is correct |
55 | Correct | 1 ms | 340 KB | Output is correct |
56 | Correct | 1 ms | 340 KB | Output is correct |
57 | Correct | 1 ms | 340 KB | Output is correct |
58 | Correct | 1 ms | 340 KB | Output is correct |
59 | Correct | 1 ms | 340 KB | Output is correct |
60 | Correct | 1 ms | 340 KB | Output is correct |
61 | Correct | 1 ms | 340 KB | Output is correct |
62 | Correct | 1 ms | 340 KB | Output is correct |
63 | Correct | 1 ms | 340 KB | Output is correct |
64 | Correct | 1 ms | 340 KB | Output is correct |
65 | Correct | 32 ms | 576 KB | Output is correct |
66 | Correct | 30 ms | 576 KB | Output is correct |
67 | Correct | 27 ms | 572 KB | Output is correct |
68 | Correct | 28 ms | 716 KB | Output is correct |
69 | Correct | 51 ms | 556 KB | Output is correct |
70 | Correct | 38 ms | 592 KB | Output is correct |
71 | Correct | 43 ms | 636 KB | Output is correct |
72 | Correct | 46 ms | 596 KB | Output is correct |
73 | Correct | 36 ms | 596 KB | Output is correct |
74 | Correct | 40 ms | 572 KB | Output is correct |
75 | Correct | 31 ms | 632 KB | Output is correct |
76 | Correct | 32 ms | 528 KB | Output is correct |
77 | Correct | 86 ms | 848 KB | Output is correct |
78 | Correct | 87 ms | 944 KB | Output is correct |
79 | Correct | 94 ms | 832 KB | Output is correct |
80 | Correct | 85 ms | 956 KB | Output is correct |
81 | Correct | 72 ms | 920 KB | Output is correct |
82 | Correct | 72 ms | 892 KB | Output is correct |
83 | Correct | 68 ms | 940 KB | Output is correct |
84 | Correct | 69 ms | 868 KB | Output is correct |
85 | Correct | 127 ms | 944 KB | Output is correct |
86 | Correct | 116 ms | 944 KB | Output is correct |
87 | Correct | 110 ms | 988 KB | Output is correct |
88 | Correct | 102 ms | 948 KB | Output is correct |
89 | Correct | 106 ms | 856 KB | Output is correct |
90 | Correct | 95 ms | 944 KB | Output is correct |
91 | Correct | 89 ms | 912 KB | Output is correct |
92 | Correct | 103 ms | 944 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 | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 0 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 | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 0 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 | 212 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 | 340 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 | 1 ms | 340 KB | Output is correct |
53 | Correct | 1 ms | 340 KB | Output is correct |
54 | Correct | 1 ms | 340 KB | Output is correct |
55 | Correct | 1 ms | 340 KB | Output is correct |
56 | Correct | 1 ms | 340 KB | Output is correct |
57 | Correct | 1 ms | 340 KB | Output is correct |
58 | Correct | 1 ms | 340 KB | Output is correct |
59 | Correct | 1 ms | 340 KB | Output is correct |
60 | Correct | 1 ms | 340 KB | Output is correct |
61 | Correct | 1 ms | 340 KB | Output is correct |
62 | Correct | 1 ms | 340 KB | Output is correct |
63 | Correct | 1 ms | 340 KB | Output is correct |
64 | Correct | 1 ms | 340 KB | Output is correct |
65 | Correct | 32 ms | 576 KB | Output is correct |
66 | Correct | 30 ms | 576 KB | Output is correct |
67 | Correct | 27 ms | 572 KB | Output is correct |
68 | Correct | 28 ms | 716 KB | Output is correct |
69 | Correct | 51 ms | 556 KB | Output is correct |
70 | Correct | 38 ms | 592 KB | Output is correct |
71 | Correct | 43 ms | 636 KB | Output is correct |
72 | Correct | 46 ms | 596 KB | Output is correct |
73 | Correct | 36 ms | 596 KB | Output is correct |
74 | Correct | 40 ms | 572 KB | Output is correct |
75 | Correct | 31 ms | 632 KB | Output is correct |
76 | Correct | 32 ms | 528 KB | Output is correct |
77 | Correct | 86 ms | 848 KB | Output is correct |
78 | Correct | 87 ms | 944 KB | Output is correct |
79 | Correct | 94 ms | 832 KB | Output is correct |
80 | Correct | 85 ms | 956 KB | Output is correct |
81 | Correct | 72 ms | 920 KB | Output is correct |
82 | Correct | 72 ms | 892 KB | Output is correct |
83 | Correct | 68 ms | 940 KB | Output is correct |
84 | Correct | 69 ms | 868 KB | Output is correct |
85 | Correct | 127 ms | 944 KB | Output is correct |
86 | Correct | 116 ms | 944 KB | Output is correct |
87 | Correct | 110 ms | 988 KB | Output is correct |
88 | Correct | 102 ms | 948 KB | Output is correct |
89 | Correct | 106 ms | 856 KB | Output is correct |
90 | Correct | 95 ms | 944 KB | Output is correct |
91 | Correct | 89 ms | 912 KB | Output is correct |
92 | Correct | 103 ms | 944 KB | Output is correct |
93 | Correct | 2661 ms | 5404 KB | Output is correct |
94 | Correct | 2650 ms | 5428 KB | Output is correct |
95 | Correct | 2785 ms | 5412 KB | Output is correct |
96 | Correct | 2280 ms | 5432 KB | Output is correct |
97 | Correct | 2092 ms | 5424 KB | Output is correct |
98 | Correct | 2209 ms | 5508 KB | Output is correct |
99 | Correct | 268 ms | 1592 KB | Output is correct |
100 | Correct | 214 ms | 1560 KB | Output is correct |
101 | Correct | 227 ms | 1500 KB | Output is correct |
102 | Correct | 205 ms | 1528 KB | Output is correct |
103 | Correct | 1413 ms | 2924 KB | Output is correct |
104 | Correct | 912 ms | 2944 KB | Output is correct |
105 | Correct | 783 ms | 2796 KB | Output is correct |
106 | Correct | 637 ms | 2836 KB | Output is correct |
107 | Execution timed out | 3090 ms | 4928 KB | Time limit exceeded |
108 | Halted | 0 ms | 0 KB | - |