답안 #1095470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095470 2024-10-02T10:40:52 Z gyg Amusement Park (CEOI19_amusementpark) C++17
100 / 100
2370 ms 4952 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define arr array 
const int MX_N = 18 + 2, MD = 998244353;

int n, m;
arr<arr<bool, MX_N>, MX_N> adj;

int md(int x) { return (x + MD) % MD; }
int expn(int x, int y) {
    if (y == 0) return 1;
    int ans = expn(x, y / 2);
    ans = md(ans * ans);
    if (y % 2 == 1) ans = md(ans * x);
    return ans;
}
int inv(int x) { return expn(x, MD - 2); }

arr<bool, 1 << MX_N> indp;
arr<int, 1 << MX_N> mltp;
void prcmp() {
    indp[0] = true;
    for (int msk = 1; msk < (1 << n); msk++) {
        for (int u = 1; u <= n; u++) {
            if (!(msk & (1 << (u - 1)))) continue;
            indp[msk] = indp[msk ^ (1 << (u - 1))];
            for (int v = 1; v <= n; v++) {
                if (!(msk & (1 << (v - 1)))) continue;
                if (v == u) continue;
                if (adj[u][v]) indp[msk] = false;
            }
            break;
        }
    }

    for (int msk = 0; msk < (1 << n); msk++) {
        int sz = 0;
        for (int u = 1; u <= n; u++) sz += (bool) (msk & (1 << (u - 1)));
        mltp[msk] = (sz % 2 == 1) ? 1 : md(-1);
    }
}

arr<int, 1 << MX_N> dp;
void cmp() {
    dp[0] = 1;
    for (int msk = 1; msk < (1 << n); msk++) 
        for (int sb_msk = msk; sb_msk != 0; sb_msk = (sb_msk - 1) & msk) 
            if (indp[sb_msk]) dp[msk] = md(dp[msk] + md(mltp[sb_msk] * dp[msk ^ sb_msk]));        
}

signed main() {
    // freopen("prk.in", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        adj[u][v] = adj[v][u] = true;
    }
    
    prcmp();
    cmp();
    
    int ans = md(md(dp[(1 << n) - 1] * m) * inv(2));
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 356 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 452 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 352 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 356 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 452 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 352 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 8 ms 604 KB Output is correct
66 Correct 8 ms 604 KB Output is correct
67 Correct 7 ms 604 KB Output is correct
68 Correct 6 ms 628 KB Output is correct
69 Correct 21 ms 600 KB Output is correct
70 Correct 15 ms 604 KB Output is correct
71 Correct 15 ms 620 KB Output is correct
72 Correct 16 ms 604 KB Output is correct
73 Correct 11 ms 604 KB Output is correct
74 Correct 11 ms 620 KB Output is correct
75 Correct 12 ms 600 KB Output is correct
76 Correct 12 ms 692 KB Output is correct
77 Correct 23 ms 856 KB Output is correct
78 Correct 22 ms 860 KB Output is correct
79 Correct 20 ms 860 KB Output is correct
80 Correct 18 ms 1004 KB Output is correct
81 Correct 24 ms 856 KB Output is correct
82 Correct 16 ms 860 KB Output is correct
83 Correct 16 ms 860 KB Output is correct
84 Correct 16 ms 964 KB Output is correct
85 Correct 60 ms 860 KB Output is correct
86 Correct 41 ms 860 KB Output is correct
87 Correct 44 ms 864 KB Output is correct
88 Correct 47 ms 856 KB Output is correct
89 Correct 30 ms 860 KB Output is correct
90 Correct 31 ms 856 KB Output is correct
91 Correct 34 ms 860 KB Output is correct
92 Correct 35 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 356 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 452 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 352 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 8 ms 604 KB Output is correct
66 Correct 8 ms 604 KB Output is correct
67 Correct 7 ms 604 KB Output is correct
68 Correct 6 ms 628 KB Output is correct
69 Correct 21 ms 600 KB Output is correct
70 Correct 15 ms 604 KB Output is correct
71 Correct 15 ms 620 KB Output is correct
72 Correct 16 ms 604 KB Output is correct
73 Correct 11 ms 604 KB Output is correct
74 Correct 11 ms 620 KB Output is correct
75 Correct 12 ms 600 KB Output is correct
76 Correct 12 ms 692 KB Output is correct
77 Correct 23 ms 856 KB Output is correct
78 Correct 22 ms 860 KB Output is correct
79 Correct 20 ms 860 KB Output is correct
80 Correct 18 ms 1004 KB Output is correct
81 Correct 24 ms 856 KB Output is correct
82 Correct 16 ms 860 KB Output is correct
83 Correct 16 ms 860 KB Output is correct
84 Correct 16 ms 964 KB Output is correct
85 Correct 60 ms 860 KB Output is correct
86 Correct 41 ms 860 KB Output is correct
87 Correct 44 ms 864 KB Output is correct
88 Correct 47 ms 856 KB Output is correct
89 Correct 30 ms 860 KB Output is correct
90 Correct 31 ms 856 KB Output is correct
91 Correct 34 ms 860 KB Output is correct
92 Correct 35 ms 860 KB Output is correct
93 Correct 1096 ms 4736 KB Output is correct
94 Correct 1106 ms 4776 KB Output is correct
95 Correct 1119 ms 4752 KB Output is correct
96 Correct 809 ms 4952 KB Output is correct
97 Correct 694 ms 4744 KB Output is correct
98 Correct 820 ms 4692 KB Output is correct
99 Correct 71 ms 1364 KB Output is correct
100 Correct 64 ms 1360 KB Output is correct
101 Correct 56 ms 1364 KB Output is correct
102 Correct 52 ms 1364 KB Output is correct
103 Correct 793 ms 2388 KB Output is correct
104 Correct 393 ms 2504 KB Output is correct
105 Correct 273 ms 2388 KB Output is correct
106 Correct 187 ms 2472 KB Output is correct
107 Correct 2370 ms 4688 KB Output is correct
108 Correct 762 ms 4692 KB Output is correct
109 Correct 512 ms 4776 KB Output is correct
110 Correct 435 ms 4688 KB Output is correct
111 Correct 49 ms 1364 KB Output is correct
112 Correct 45 ms 1368 KB Output is correct
113 Correct 45 ms 1512 KB Output is correct
114 Correct 182 ms 1512 KB Output is correct
115 Correct 120 ms 1364 KB Output is correct
116 Correct 132 ms 1360 KB Output is correct
117 Correct 138 ms 1320 KB Output is correct
118 Correct 87 ms 1404 KB Output is correct
119 Correct 93 ms 1460 KB Output is correct
120 Correct 100 ms 1520 KB Output is correct
121 Correct 103 ms 1448 KB Output is correct
122 Correct 155 ms 2540 KB Output is correct
123 Correct 135 ms 2596 KB Output is correct
124 Correct 129 ms 2384 KB Output is correct
125 Correct 124 ms 2388 KB Output is correct
126 Correct 125 ms 2648 KB Output is correct
127 Correct 115 ms 2600 KB Output is correct
128 Correct 108 ms 2388 KB Output is correct
129 Correct 110 ms 2472 KB Output is correct
130 Correct 114 ms 2620 KB Output is correct
131 Correct 542 ms 2388 KB Output is correct
132 Correct 380 ms 2388 KB Output is correct
133 Correct 391 ms 2388 KB Output is correct
134 Correct 406 ms 2432 KB Output is correct
135 Correct 257 ms 2384 KB Output is correct
136 Correct 273 ms 2384 KB Output is correct
137 Correct 294 ms 2384 KB Output is correct
138 Correct 305 ms 2456 KB Output is correct
139 Correct 192 ms 2436 KB Output is correct
140 Correct 215 ms 2420 KB Output is correct
141 Correct 238 ms 2500 KB Output is correct
142 Correct 367 ms 4740 KB Output is correct
143 Correct 348 ms 4628 KB Output is correct
144 Correct 342 ms 4712 KB Output is correct
145 Correct 320 ms 4688 KB Output is correct
146 Correct 314 ms 4692 KB Output is correct
147 Correct 325 ms 4664 KB Output is correct
148 Correct 380 ms 4584 KB Output is correct
149 Correct 373 ms 4692 KB Output is correct
150 Correct 363 ms 4664 KB Output is correct
151 Correct 539 ms 4692 KB Output is correct
152 Correct 527 ms 4656 KB Output is correct
153 Correct 810 ms 4572 KB Output is correct
154 Correct 784 ms 4692 KB Output is correct
155 Correct 856 ms 4764 KB Output is correct
156 Correct 902 ms 4780 KB Output is correct
157 Correct 818 ms 4688 KB Output is correct
158 Correct 871 ms 4696 KB Output is correct
159 Correct 601 ms 4948 KB Output is correct
160 Correct 633 ms 4716 KB Output is correct
161 Correct 696 ms 4692 KB Output is correct
162 Correct 473 ms 4688 KB Output is correct
163 Correct 475 ms 4796 KB Output is correct
164 Correct 508 ms 4692 KB Output is correct
165 Correct 531 ms 4780 KB Output is correct
166 Correct 551 ms 4688 KB Output is correct
167 Correct 563 ms 4772 KB Output is correct