Submission #1111241

# Submission time Handle Problem Language Result Execution time Memory
1111241 2024-11-11T20:13:04 Z Thunnus Amusement Park (CEOI19_amusementpark) C++17
100 / 100
2229 ms 10976 KB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()

const int MAXN = 18;
const int MOD = 998244353;
int adj[1 << MAXN], popcnt[1 << MAXN], pie[1 << MAXN], nodeid[1 << MAXN], f[1 << MAXN];
bool indepset[1 << MAXN];

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m, u, v;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> u >> v;
        u--, v--;
        adj[u] |= (1ll << v);
        adj[v] |= (1ll << u);
    }
    for(int i = 0; i < n; i++){
        nodeid[1ll << i] = i;
    }
    for(int i = 0; i < (1ll << n); i++){
        popcnt[i] = popcnt[i >> 1] + (i & 1);
        pie[i] = (popcnt[i] % 2) * 2 - 1;
    }

    indepset[0] = true;
    for(int i = 1; i < (1ll << n); i++){
        if(indepset[i & (i - 1)] && ((adj[nodeid[i & -i]] & (i & (i - 1))) == 0)){ // deciding whether the subset including the nodes in the mask id DAG
            indepset[i] = true;
        }
    }

    f[0] = 1;
    for(int i = 1; i < (1ll << n); i++){ // O(3^n)
        for(int j = i; j; j = (j - 1) & i){
            if(indepset[j]){
                f[i] = (f[i] + pie[j] * f[i ^ j]) % MOD; // PIE
            }
        }
    }
    f[(1 << n) - 1] = (f[(1 << n) - 1] + MOD) % MOD;
	cout << f[(1 << n) - 1] * m % MOD * ((MOD + 1) / 2) % MOD; // (MODE + 1) / 2 is the modular inverse of 2.
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 4688 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 4688 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2512 KB Output is correct
25 Correct 2 ms 2384 KB Output is correct
26 Correct 1 ms 2512 KB Output is correct
27 Correct 1 ms 2552 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2556 KB Output is correct
31 Correct 2 ms 4432 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 2 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 4432 KB Output is correct
39 Correct 1 ms 4432 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 2 ms 4432 KB Output is correct
42 Correct 1 ms 2384 KB Output is correct
43 Correct 1 ms 2384 KB Output is correct
44 Correct 1 ms 2384 KB Output is correct
45 Correct 1 ms 2384 KB Output is correct
46 Correct 1 ms 2384 KB Output is correct
47 Correct 1 ms 2640 KB Output is correct
48 Correct 1 ms 2384 KB Output is correct
49 Correct 1 ms 2384 KB Output is correct
50 Correct 1 ms 2384 KB Output is correct
51 Correct 1 ms 2384 KB Output is correct
52 Correct 1 ms 2384 KB Output is correct
53 Correct 1 ms 2384 KB Output is correct
54 Correct 1 ms 2384 KB Output is correct
55 Correct 1 ms 2384 KB Output is correct
56 Correct 1 ms 2384 KB Output is correct
57 Correct 1 ms 2384 KB Output is correct
58 Correct 1 ms 2384 KB Output is correct
59 Correct 1 ms 2384 KB Output is correct
60 Correct 1 ms 2384 KB Output is correct
61 Correct 1 ms 2512 KB Output is correct
62 Correct 1 ms 2384 KB Output is correct
63 Correct 1 ms 2384 KB Output is correct
64 Correct 1 ms 2576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 4688 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2512 KB Output is correct
25 Correct 2 ms 2384 KB Output is correct
26 Correct 1 ms 2512 KB Output is correct
27 Correct 1 ms 2552 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2556 KB Output is correct
31 Correct 2 ms 4432 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 2 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 4432 KB Output is correct
39 Correct 1 ms 4432 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 2 ms 4432 KB Output is correct
42 Correct 1 ms 2384 KB Output is correct
43 Correct 1 ms 2384 KB Output is correct
44 Correct 1 ms 2384 KB Output is correct
45 Correct 1 ms 2384 KB Output is correct
46 Correct 1 ms 2384 KB Output is correct
47 Correct 1 ms 2640 KB Output is correct
48 Correct 1 ms 2384 KB Output is correct
49 Correct 1 ms 2384 KB Output is correct
50 Correct 1 ms 2384 KB Output is correct
51 Correct 1 ms 2384 KB Output is correct
52 Correct 1 ms 2384 KB Output is correct
53 Correct 1 ms 2384 KB Output is correct
54 Correct 1 ms 2384 KB Output is correct
55 Correct 1 ms 2384 KB Output is correct
56 Correct 1 ms 2384 KB Output is correct
57 Correct 1 ms 2384 KB Output is correct
58 Correct 1 ms 2384 KB Output is correct
59 Correct 1 ms 2384 KB Output is correct
60 Correct 1 ms 2384 KB Output is correct
61 Correct 1 ms 2512 KB Output is correct
62 Correct 1 ms 2384 KB Output is correct
63 Correct 1 ms 2384 KB Output is correct
64 Correct 1 ms 2576 KB Output is correct
65 Correct 8 ms 2896 KB Output is correct
66 Correct 7 ms 2896 KB Output is correct
67 Correct 7 ms 2896 KB Output is correct
68 Correct 6 ms 2896 KB Output is correct
69 Correct 17 ms 2772 KB Output is correct
70 Correct 12 ms 2908 KB Output is correct
71 Correct 14 ms 2896 KB Output is correct
72 Correct 16 ms 2896 KB Output is correct
73 Correct 11 ms 2896 KB Output is correct
74 Correct 11 ms 2896 KB Output is correct
75 Correct 12 ms 2908 KB Output is correct
76 Correct 12 ms 2912 KB Output is correct
77 Correct 20 ms 3152 KB Output is correct
78 Correct 19 ms 3320 KB Output is correct
79 Correct 17 ms 3152 KB Output is correct
80 Correct 16 ms 3152 KB Output is correct
81 Correct 16 ms 3312 KB Output is correct
82 Correct 16 ms 3152 KB Output is correct
83 Correct 19 ms 3152 KB Output is correct
84 Correct 15 ms 3152 KB Output is correct
85 Correct 57 ms 3152 KB Output is correct
86 Correct 38 ms 3124 KB Output is correct
87 Correct 40 ms 3152 KB Output is correct
88 Correct 43 ms 3324 KB Output is correct
89 Correct 26 ms 3152 KB Output is correct
90 Correct 29 ms 7148 KB Output is correct
91 Correct 35 ms 3152 KB Output is correct
92 Correct 32 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 4688 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2512 KB Output is correct
25 Correct 2 ms 2384 KB Output is correct
26 Correct 1 ms 2512 KB Output is correct
27 Correct 1 ms 2552 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2556 KB Output is correct
31 Correct 2 ms 4432 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 2 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 4432 KB Output is correct
39 Correct 1 ms 4432 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 2 ms 4432 KB Output is correct
42 Correct 1 ms 2384 KB Output is correct
43 Correct 1 ms 2384 KB Output is correct
44 Correct 1 ms 2384 KB Output is correct
45 Correct 1 ms 2384 KB Output is correct
46 Correct 1 ms 2384 KB Output is correct
47 Correct 1 ms 2640 KB Output is correct
48 Correct 1 ms 2384 KB Output is correct
49 Correct 1 ms 2384 KB Output is correct
50 Correct 1 ms 2384 KB Output is correct
51 Correct 1 ms 2384 KB Output is correct
52 Correct 1 ms 2384 KB Output is correct
53 Correct 1 ms 2384 KB Output is correct
54 Correct 1 ms 2384 KB Output is correct
55 Correct 1 ms 2384 KB Output is correct
56 Correct 1 ms 2384 KB Output is correct
57 Correct 1 ms 2384 KB Output is correct
58 Correct 1 ms 2384 KB Output is correct
59 Correct 1 ms 2384 KB Output is correct
60 Correct 1 ms 2384 KB Output is correct
61 Correct 1 ms 2512 KB Output is correct
62 Correct 1 ms 2384 KB Output is correct
63 Correct 1 ms 2384 KB Output is correct
64 Correct 1 ms 2576 KB Output is correct
65 Correct 8 ms 2896 KB Output is correct
66 Correct 7 ms 2896 KB Output is correct
67 Correct 7 ms 2896 KB Output is correct
68 Correct 6 ms 2896 KB Output is correct
69 Correct 17 ms 2772 KB Output is correct
70 Correct 12 ms 2908 KB Output is correct
71 Correct 14 ms 2896 KB Output is correct
72 Correct 16 ms 2896 KB Output is correct
73 Correct 11 ms 2896 KB Output is correct
74 Correct 11 ms 2896 KB Output is correct
75 Correct 12 ms 2908 KB Output is correct
76 Correct 12 ms 2912 KB Output is correct
77 Correct 20 ms 3152 KB Output is correct
78 Correct 19 ms 3320 KB Output is correct
79 Correct 17 ms 3152 KB Output is correct
80 Correct 16 ms 3152 KB Output is correct
81 Correct 16 ms 3312 KB Output is correct
82 Correct 16 ms 3152 KB Output is correct
83 Correct 19 ms 3152 KB Output is correct
84 Correct 15 ms 3152 KB Output is correct
85 Correct 57 ms 3152 KB Output is correct
86 Correct 38 ms 3124 KB Output is correct
87 Correct 40 ms 3152 KB Output is correct
88 Correct 43 ms 3324 KB Output is correct
89 Correct 26 ms 3152 KB Output is correct
90 Correct 29 ms 7148 KB Output is correct
91 Correct 35 ms 3152 KB Output is correct
92 Correct 32 ms 3152 KB Output is correct
93 Correct 1008 ms 8824 KB Output is correct
94 Correct 1028 ms 10700 KB Output is correct
95 Correct 1000 ms 10688 KB Output is correct
96 Correct 698 ms 10976 KB Output is correct
97 Correct 594 ms 8868 KB Output is correct
98 Correct 754 ms 8776 KB Output is correct
99 Correct 63 ms 3912 KB Output is correct
100 Correct 55 ms 3920 KB Output is correct
101 Correct 49 ms 4012 KB Output is correct
102 Correct 46 ms 3920 KB Output is correct
103 Correct 753 ms 5704 KB Output is correct
104 Correct 357 ms 5532 KB Output is correct
105 Correct 263 ms 5704 KB Output is correct
106 Correct 177 ms 5704 KB Output is correct
107 Correct 2229 ms 8764 KB Output is correct
108 Correct 667 ms 8796 KB Output is correct
109 Correct 508 ms 10664 KB Output is correct
110 Correct 394 ms 10620 KB Output is correct
111 Correct 44 ms 6000 KB Output is correct
112 Correct 46 ms 3920 KB Output is correct
113 Correct 39 ms 7504 KB Output is correct
114 Correct 160 ms 6064 KB Output is correct
115 Correct 109 ms 4040 KB Output is correct
116 Correct 116 ms 3932 KB Output is correct
117 Correct 125 ms 4032 KB Output is correct
118 Correct 76 ms 5968 KB Output is correct
119 Correct 87 ms 4000 KB Output is correct
120 Correct 90 ms 3988 KB Output is correct
121 Correct 97 ms 6096 KB Output is correct
122 Correct 136 ms 7496 KB Output is correct
123 Correct 124 ms 7660 KB Output is correct
124 Correct 128 ms 5572 KB Output is correct
125 Correct 114 ms 7496 KB Output is correct
126 Correct 109 ms 5620 KB Output is correct
127 Correct 106 ms 5448 KB Output is correct
128 Correct 100 ms 5536 KB Output is correct
129 Correct 117 ms 5532 KB Output is correct
130 Correct 96 ms 5444 KB Output is correct
131 Correct 480 ms 5704 KB Output is correct
132 Correct 332 ms 5752 KB Output is correct
133 Correct 341 ms 5448 KB Output is correct
134 Correct 382 ms 5448 KB Output is correct
135 Correct 236 ms 7612 KB Output is correct
136 Correct 258 ms 7580 KB Output is correct
137 Correct 278 ms 7496 KB Output is correct
138 Correct 272 ms 5448 KB Output is correct
139 Correct 163 ms 5704 KB Output is correct
140 Correct 206 ms 5704 KB Output is correct
141 Correct 205 ms 7500 KB Output is correct
142 Correct 350 ms 8596 KB Output is correct
143 Correct 315 ms 10568 KB Output is correct
144 Correct 329 ms 10564 KB Output is correct
145 Correct 321 ms 10496 KB Output is correct
146 Correct 287 ms 8520 KB Output is correct
147 Correct 290 ms 8628 KB Output is correct
148 Correct 369 ms 8636 KB Output is correct
149 Correct 328 ms 8528 KB Output is correct
150 Correct 339 ms 8680 KB Output is correct
151 Correct 480 ms 8476 KB Output is correct
152 Correct 501 ms 8520 KB Output is correct
153 Correct 735 ms 8632 KB Output is correct
154 Correct 711 ms 8780 KB Output is correct
155 Correct 792 ms 8740 KB Output is correct
156 Correct 841 ms 8520 KB Output is correct
157 Correct 746 ms 10632 KB Output is correct
158 Correct 796 ms 10444 KB Output is correct
159 Correct 533 ms 8792 KB Output is correct
160 Correct 608 ms 10500 KB Output is correct
161 Correct 649 ms 10544 KB Output is correct
162 Correct 430 ms 10600 KB Output is correct
163 Correct 429 ms 10572 KB Output is correct
164 Correct 450 ms 10568 KB Output is correct
165 Correct 494 ms 8608 KB Output is correct
166 Correct 525 ms 8652 KB Output is correct
167 Correct 547 ms 10568 KB Output is correct