#include <iostream>
#include <array>
#include <algorithm>
using ll = long long;
const int MAX_N = 18 + 1;
const int MOD = 998244353;
std::array<std::array<bool, MAX_N>, MAX_N> graph;
std::array<ll, (1 << MAX_N)> dp, sSize;
std::array<bool, (1 << MAX_N)> sInd;
ll solve(int n) {
sInd.fill(true);
for (int s = 0; s < (1 << n); ++s) {
int c = 0;
for (int i = 0; i < n; ++i) {
if (s & (1 << i)) {
for (int j = 0; j < n; ++j) {
if (s & (1 << j)) {
if (graph[i][j]) {
sInd[s] = false;
}
}
}
c++;
}
}
sSize[s] = c;
}
dp[0] = 1;
for (int s = 1; s < (1 << n); ++s) {
std::vector<int> ones;
for (int i = 0; i < n; ++i) {
if ((1 << i) & s) {
ones.push_back(i);
}
}
for (int ss = 1; ss < (1 << ones.size()); ++ss) {
int ssI = 0;
for (int j = 0; j < ones.size(); ++j) {
if (ss & (1 << j)) {
ssI += (1 << ones[j]);
}
}
if (sInd[ssI]) {
if ((sSize[ssI] % 2) == 1) {
dp[s] = (dp[s] + dp[s - ssI] + 2 * MOD) % MOD;
} else {
dp[s] = (dp[s] - dp[s - ssI] + 2 * MOD) % MOD;
}
}
}
}
return dp[(1 << n) - 1];
}
int main() {
int n, m; std::cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b; std::cin >> a >> b; a--; b--;
graph[a][b] = true;
graph[b][a] = true;
}
std::cout << (m * solve(n) / 2) % MOD << std::endl;
}
Compilation message
amusementpark.cpp: In function 'll solve(int)':
amusementpark.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int j = 0; j < ones.size(); ++j) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
2 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
2 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
1 ms |
4700 KB |
Output is correct |
32 |
Correct |
1 ms |
4524 KB |
Output is correct |
33 |
Correct |
1 ms |
4536 KB |
Output is correct |
34 |
Correct |
1 ms |
4700 KB |
Output is correct |
35 |
Correct |
1 ms |
4700 KB |
Output is correct |
36 |
Correct |
1 ms |
4700 KB |
Output is correct |
37 |
Correct |
1 ms |
4700 KB |
Output is correct |
38 |
Correct |
1 ms |
4700 KB |
Output is correct |
39 |
Correct |
1 ms |
4700 KB |
Output is correct |
40 |
Correct |
1 ms |
4700 KB |
Output is correct |
41 |
Correct |
2 ms |
4700 KB |
Output is correct |
42 |
Correct |
1 ms |
4700 KB |
Output is correct |
43 |
Correct |
2 ms |
4700 KB |
Output is correct |
44 |
Correct |
1 ms |
4700 KB |
Output is correct |
45 |
Correct |
1 ms |
4700 KB |
Output is correct |
46 |
Correct |
2 ms |
4696 KB |
Output is correct |
47 |
Correct |
1 ms |
4700 KB |
Output is correct |
48 |
Correct |
1 ms |
4700 KB |
Output is correct |
49 |
Correct |
1 ms |
4696 KB |
Output is correct |
50 |
Correct |
1 ms |
4696 KB |
Output is correct |
51 |
Correct |
1 ms |
4696 KB |
Output is correct |
52 |
Correct |
3 ms |
4724 KB |
Output is correct |
53 |
Correct |
2 ms |
4700 KB |
Output is correct |
54 |
Correct |
2 ms |
4724 KB |
Output is correct |
55 |
Correct |
2 ms |
4696 KB |
Output is correct |
56 |
Correct |
2 ms |
4700 KB |
Output is correct |
57 |
Correct |
2 ms |
4700 KB |
Output is correct |
58 |
Correct |
2 ms |
4700 KB |
Output is correct |
59 |
Correct |
2 ms |
4700 KB |
Output is correct |
60 |
Correct |
2 ms |
4700 KB |
Output is correct |
61 |
Correct |
2 ms |
4700 KB |
Output is correct |
62 |
Correct |
2 ms |
4700 KB |
Output is correct |
63 |
Correct |
2 ms |
4700 KB |
Output is correct |
64 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
2 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
1 ms |
4700 KB |
Output is correct |
32 |
Correct |
1 ms |
4524 KB |
Output is correct |
33 |
Correct |
1 ms |
4536 KB |
Output is correct |
34 |
Correct |
1 ms |
4700 KB |
Output is correct |
35 |
Correct |
1 ms |
4700 KB |
Output is correct |
36 |
Correct |
1 ms |
4700 KB |
Output is correct |
37 |
Correct |
1 ms |
4700 KB |
Output is correct |
38 |
Correct |
1 ms |
4700 KB |
Output is correct |
39 |
Correct |
1 ms |
4700 KB |
Output is correct |
40 |
Correct |
1 ms |
4700 KB |
Output is correct |
41 |
Correct |
2 ms |
4700 KB |
Output is correct |
42 |
Correct |
1 ms |
4700 KB |
Output is correct |
43 |
Correct |
2 ms |
4700 KB |
Output is correct |
44 |
Correct |
1 ms |
4700 KB |
Output is correct |
45 |
Correct |
1 ms |
4700 KB |
Output is correct |
46 |
Correct |
2 ms |
4696 KB |
Output is correct |
47 |
Correct |
1 ms |
4700 KB |
Output is correct |
48 |
Correct |
1 ms |
4700 KB |
Output is correct |
49 |
Correct |
1 ms |
4696 KB |
Output is correct |
50 |
Correct |
1 ms |
4696 KB |
Output is correct |
51 |
Correct |
1 ms |
4696 KB |
Output is correct |
52 |
Correct |
3 ms |
4724 KB |
Output is correct |
53 |
Correct |
2 ms |
4700 KB |
Output is correct |
54 |
Correct |
2 ms |
4724 KB |
Output is correct |
55 |
Correct |
2 ms |
4696 KB |
Output is correct |
56 |
Correct |
2 ms |
4700 KB |
Output is correct |
57 |
Correct |
2 ms |
4700 KB |
Output is correct |
58 |
Correct |
2 ms |
4700 KB |
Output is correct |
59 |
Correct |
2 ms |
4700 KB |
Output is correct |
60 |
Correct |
2 ms |
4700 KB |
Output is correct |
61 |
Correct |
2 ms |
4700 KB |
Output is correct |
62 |
Correct |
2 ms |
4700 KB |
Output is correct |
63 |
Correct |
2 ms |
4700 KB |
Output is correct |
64 |
Correct |
2 ms |
4700 KB |
Output is correct |
65 |
Correct |
195 ms |
4700 KB |
Output is correct |
66 |
Correct |
196 ms |
4700 KB |
Output is correct |
67 |
Correct |
193 ms |
4700 KB |
Output is correct |
68 |
Correct |
193 ms |
4700 KB |
Output is correct |
69 |
Correct |
217 ms |
4700 KB |
Output is correct |
70 |
Correct |
209 ms |
4700 KB |
Output is correct |
71 |
Correct |
205 ms |
4700 KB |
Output is correct |
72 |
Correct |
192 ms |
4700 KB |
Output is correct |
73 |
Correct |
195 ms |
4700 KB |
Output is correct |
74 |
Correct |
200 ms |
4700 KB |
Output is correct |
75 |
Correct |
199 ms |
4696 KB |
Output is correct |
76 |
Correct |
188 ms |
4696 KB |
Output is correct |
77 |
Correct |
642 ms |
4948 KB |
Output is correct |
78 |
Correct |
637 ms |
4700 KB |
Output is correct |
79 |
Correct |
636 ms |
4724 KB |
Output is correct |
80 |
Incorrect |
647 ms |
4704 KB |
Output isn't correct |
81 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
2 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
1 ms |
4700 KB |
Output is correct |
32 |
Correct |
1 ms |
4524 KB |
Output is correct |
33 |
Correct |
1 ms |
4536 KB |
Output is correct |
34 |
Correct |
1 ms |
4700 KB |
Output is correct |
35 |
Correct |
1 ms |
4700 KB |
Output is correct |
36 |
Correct |
1 ms |
4700 KB |
Output is correct |
37 |
Correct |
1 ms |
4700 KB |
Output is correct |
38 |
Correct |
1 ms |
4700 KB |
Output is correct |
39 |
Correct |
1 ms |
4700 KB |
Output is correct |
40 |
Correct |
1 ms |
4700 KB |
Output is correct |
41 |
Correct |
2 ms |
4700 KB |
Output is correct |
42 |
Correct |
1 ms |
4700 KB |
Output is correct |
43 |
Correct |
2 ms |
4700 KB |
Output is correct |
44 |
Correct |
1 ms |
4700 KB |
Output is correct |
45 |
Correct |
1 ms |
4700 KB |
Output is correct |
46 |
Correct |
2 ms |
4696 KB |
Output is correct |
47 |
Correct |
1 ms |
4700 KB |
Output is correct |
48 |
Correct |
1 ms |
4700 KB |
Output is correct |
49 |
Correct |
1 ms |
4696 KB |
Output is correct |
50 |
Correct |
1 ms |
4696 KB |
Output is correct |
51 |
Correct |
1 ms |
4696 KB |
Output is correct |
52 |
Correct |
3 ms |
4724 KB |
Output is correct |
53 |
Correct |
2 ms |
4700 KB |
Output is correct |
54 |
Correct |
2 ms |
4724 KB |
Output is correct |
55 |
Correct |
2 ms |
4696 KB |
Output is correct |
56 |
Correct |
2 ms |
4700 KB |
Output is correct |
57 |
Correct |
2 ms |
4700 KB |
Output is correct |
58 |
Correct |
2 ms |
4700 KB |
Output is correct |
59 |
Correct |
2 ms |
4700 KB |
Output is correct |
60 |
Correct |
2 ms |
4700 KB |
Output is correct |
61 |
Correct |
2 ms |
4700 KB |
Output is correct |
62 |
Correct |
2 ms |
4700 KB |
Output is correct |
63 |
Correct |
2 ms |
4700 KB |
Output is correct |
64 |
Correct |
2 ms |
4700 KB |
Output is correct |
65 |
Correct |
195 ms |
4700 KB |
Output is correct |
66 |
Correct |
196 ms |
4700 KB |
Output is correct |
67 |
Correct |
193 ms |
4700 KB |
Output is correct |
68 |
Correct |
193 ms |
4700 KB |
Output is correct |
69 |
Correct |
217 ms |
4700 KB |
Output is correct |
70 |
Correct |
209 ms |
4700 KB |
Output is correct |
71 |
Correct |
205 ms |
4700 KB |
Output is correct |
72 |
Correct |
192 ms |
4700 KB |
Output is correct |
73 |
Correct |
195 ms |
4700 KB |
Output is correct |
74 |
Correct |
200 ms |
4700 KB |
Output is correct |
75 |
Correct |
199 ms |
4696 KB |
Output is correct |
76 |
Correct |
188 ms |
4696 KB |
Output is correct |
77 |
Correct |
642 ms |
4948 KB |
Output is correct |
78 |
Correct |
637 ms |
4700 KB |
Output is correct |
79 |
Correct |
636 ms |
4724 KB |
Output is correct |
80 |
Incorrect |
647 ms |
4704 KB |
Output isn't correct |
81 |
Halted |
0 ms |
0 KB |
- |