Submission #572989

# Submission time Handle Problem Language Result Execution time Memory
572989 2022-06-05T15:22:46 Z piOOE Amusement Park (CEOI19_amusementpark) C++17
100 / 100
2040 ms 1816 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;

typedef long long ll;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }

const int N = 18, MOD = 998244353;

int dp[1 << N];
bool ok[1 << N];

int add(int a, int b) {
    return a + b < MOD ? a + b : a + b - MOD;
}

int mul(int a, int b) {
    return a * (ll) b % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(ok, 1, sizeof(ok));
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        ok[(1 << a) | (1 << b)] = false;
    }
    for (int mask = 1; mask < (1 << n); ++mask) {
        for (int i = 0; i < n; ++i) {
            if ((mask & (1 << i)) && !ok[mask ^ (1 << i)]) {
                ok[mask] = false;
                break;
            }
        }
    }
    dp[0] = 1;
    for (int mask = 1; mask < (1 << n); ++mask) {
        for (int msk = mask; msk > 0; msk = (msk - 1) & mask) {
            if (!ok[msk]) {
                continue;
            }
            if (__builtin_popcount(msk) & 1) {
                dp[mask] = add(dp[mask], dp[mask ^ msk]);
            } else {
                dp[mask] = add(dp[mask], MOD - dp[mask ^ msk]);
            }
        }
    }
    cout << mul(dp[(1 << n) - 1], mul(m, (MOD + 1) >> 1));
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 0 ms 468 KB Output is correct
33 Correct 0 ms 468 KB Output is correct
34 Correct 0 ms 468 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 0 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 544 KB Output is correct
45 Correct 0 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 0 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 0 ms 468 KB Output is correct
50 Correct 0 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 496 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 0 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 0 ms 468 KB Output is correct
33 Correct 0 ms 468 KB Output is correct
34 Correct 0 ms 468 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 0 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 544 KB Output is correct
45 Correct 0 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 0 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 0 ms 468 KB Output is correct
50 Correct 0 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 496 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 0 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 10 ms 616 KB Output is correct
66 Correct 10 ms 596 KB Output is correct
67 Correct 9 ms 596 KB Output is correct
68 Correct 8 ms 596 KB Output is correct
69 Correct 20 ms 596 KB Output is correct
70 Correct 16 ms 596 KB Output is correct
71 Correct 16 ms 596 KB Output is correct
72 Correct 14 ms 596 KB Output is correct
73 Correct 13 ms 596 KB Output is correct
74 Correct 13 ms 616 KB Output is correct
75 Correct 12 ms 596 KB Output is correct
76 Correct 12 ms 596 KB Output is correct
77 Correct 34 ms 616 KB Output is correct
78 Correct 29 ms 596 KB Output is correct
79 Correct 28 ms 680 KB Output is correct
80 Correct 25 ms 676 KB Output is correct
81 Correct 23 ms 724 KB Output is correct
82 Correct 24 ms 696 KB Output is correct
83 Correct 20 ms 684 KB Output is correct
84 Correct 19 ms 596 KB Output is correct
85 Correct 60 ms 688 KB Output is correct
86 Correct 46 ms 692 KB Output is correct
87 Correct 44 ms 668 KB Output is correct
88 Correct 42 ms 680 KB Output is correct
89 Correct 38 ms 596 KB Output is correct
90 Correct 36 ms 664 KB Output is correct
91 Correct 35 ms 764 KB Output is correct
92 Correct 34 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 0 ms 468 KB Output is correct
33 Correct 0 ms 468 KB Output is correct
34 Correct 0 ms 468 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 0 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 544 KB Output is correct
45 Correct 0 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 0 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 0 ms 468 KB Output is correct
50 Correct 0 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 496 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 0 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 10 ms 616 KB Output is correct
66 Correct 10 ms 596 KB Output is correct
67 Correct 9 ms 596 KB Output is correct
68 Correct 8 ms 596 KB Output is correct
69 Correct 20 ms 596 KB Output is correct
70 Correct 16 ms 596 KB Output is correct
71 Correct 16 ms 596 KB Output is correct
72 Correct 14 ms 596 KB Output is correct
73 Correct 13 ms 596 KB Output is correct
74 Correct 13 ms 616 KB Output is correct
75 Correct 12 ms 596 KB Output is correct
76 Correct 12 ms 596 KB Output is correct
77 Correct 34 ms 616 KB Output is correct
78 Correct 29 ms 596 KB Output is correct
79 Correct 28 ms 680 KB Output is correct
80 Correct 25 ms 676 KB Output is correct
81 Correct 23 ms 724 KB Output is correct
82 Correct 24 ms 696 KB Output is correct
83 Correct 20 ms 684 KB Output is correct
84 Correct 19 ms 596 KB Output is correct
85 Correct 60 ms 688 KB Output is correct
86 Correct 46 ms 692 KB Output is correct
87 Correct 44 ms 668 KB Output is correct
88 Correct 42 ms 680 KB Output is correct
89 Correct 38 ms 596 KB Output is correct
90 Correct 36 ms 664 KB Output is correct
91 Correct 35 ms 764 KB Output is correct
92 Correct 34 ms 608 KB Output is correct
93 Correct 1233 ms 1660 KB Output is correct
94 Correct 1249 ms 1680 KB Output is correct
95 Correct 1255 ms 1496 KB Output is correct
96 Correct 990 ms 1816 KB Output is correct
97 Correct 867 ms 1496 KB Output is correct
98 Correct 935 ms 1580 KB Output is correct
99 Correct 102 ms 716 KB Output is correct
100 Correct 83 ms 784 KB Output is correct
101 Correct 77 ms 732 KB Output is correct
102 Correct 71 ms 796 KB Output is correct
103 Correct 658 ms 1052 KB Output is correct
104 Correct 397 ms 1124 KB Output is correct
105 Correct 319 ms 1076 KB Output is correct
106 Correct 258 ms 1012 KB Output is correct
107 Correct 2040 ms 1596 KB Output is correct
108 Correct 883 ms 1776 KB Output is correct
109 Correct 684 ms 1588 KB Output is correct
110 Correct 562 ms 1584 KB Output is correct
111 Correct 65 ms 1008 KB Output is correct
112 Correct 58 ms 708 KB Output is correct
113 Correct 54 ms 812 KB Output is correct
114 Correct 173 ms 752 KB Output is correct
115 Correct 134 ms 824 KB Output is correct
116 Correct 128 ms 784 KB Output is correct
117 Correct 126 ms 732 KB Output is correct
118 Correct 109 ms 740 KB Output is correct
119 Correct 103 ms 772 KB Output is correct
120 Correct 101 ms 800 KB Output is correct
121 Correct 101 ms 716 KB Output is correct
122 Correct 209 ms 988 KB Output is correct
123 Correct 179 ms 1032 KB Output is correct
124 Correct 165 ms 1008 KB Output is correct
125 Correct 169 ms 1236 KB Output is correct
126 Correct 150 ms 1056 KB Output is correct
127 Correct 139 ms 1088 KB Output is correct
128 Correct 132 ms 976 KB Output is correct
129 Correct 130 ms 1152 KB Output is correct
130 Correct 128 ms 1012 KB Output is correct
131 Correct 514 ms 1004 KB Output is correct
132 Correct 408 ms 1080 KB Output is correct
133 Correct 378 ms 1072 KB Output is correct
134 Correct 367 ms 1076 KB Output is correct
135 Correct 335 ms 1120 KB Output is correct
136 Correct 312 ms 1068 KB Output is correct
137 Correct 296 ms 1060 KB Output is correct
138 Correct 293 ms 1060 KB Output is correct
139 Correct 280 ms 1120 KB Output is correct
140 Correct 252 ms 1024 KB Output is correct
141 Correct 238 ms 1040 KB Output is correct
142 Correct 493 ms 1536 KB Output is correct
143 Correct 475 ms 1552 KB Output is correct
144 Correct 429 ms 1572 KB Output is correct
145 Correct 401 ms 1580 KB Output is correct
146 Correct 381 ms 1484 KB Output is correct
147 Correct 364 ms 1580 KB Output is correct
148 Correct 495 ms 1540 KB Output is correct
149 Correct 485 ms 1592 KB Output is correct
150 Correct 506 ms 1588 KB Output is correct
151 Correct 613 ms 1584 KB Output is correct
152 Correct 613 ms 1472 KB Output is correct
153 Correct 992 ms 1656 KB Output is correct
154 Correct 959 ms 1516 KB Output is correct
155 Correct 889 ms 1580 KB Output is correct
156 Correct 866 ms 1476 KB Output is correct
157 Correct 923 ms 1544 KB Output is correct
158 Correct 883 ms 1620 KB Output is correct
159 Correct 841 ms 1580 KB Output is correct
160 Correct 725 ms 1692 KB Output is correct
161 Correct 688 ms 1588 KB Output is correct
162 Correct 750 ms 1636 KB Output is correct
163 Correct 666 ms 1604 KB Output is correct
164 Correct 625 ms 1580 KB Output is correct
165 Correct 607 ms 1768 KB Output is correct
166 Correct 585 ms 1656 KB Output is correct
167 Correct 573 ms 1564 KB Output is correct