Submission #573001

# Submission time Handle Problem Language Result Execution time Memory
573001 2022-06-05T15:41:55 Z piOOE Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1487 ms 2892 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], popc[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) {
        popc[mask] = popc[mask & mask - 1] + 1;
        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 (popc[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;
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:41:39: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   41 |         popc[mask] = popc[mask & mask - 1] + 1;
      |                                  ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 1 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 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 0 ms 596 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 1 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 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 0 ms 596 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 0 ms 596 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 0 ms 492 KB Output is correct
33 Correct 0 ms 468 KB Output is correct
34 Correct 0 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 0 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 1 ms 468 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 0 ms 468 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 552 KB Output is correct
47 Correct 0 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 520 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 596 KB Output is correct
53 Correct 1 ms 596 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 1 ms 596 KB Output is correct
59 Correct 1 ms 596 KB Output is correct
60 Correct 1 ms 596 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 596 KB Output is correct
63 Correct 1 ms 596 KB Output is correct
64 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 1 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 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 0 ms 596 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 0 ms 596 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 0 ms 492 KB Output is correct
33 Correct 0 ms 468 KB Output is correct
34 Correct 0 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 0 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 1 ms 468 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 0 ms 468 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 552 KB Output is correct
47 Correct 0 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 520 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 596 KB Output is correct
53 Correct 1 ms 596 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 1 ms 596 KB Output is correct
59 Correct 1 ms 596 KB Output is correct
60 Correct 1 ms 596 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 596 KB Output is correct
63 Correct 1 ms 596 KB Output is correct
64 Correct 1 ms 596 KB Output is correct
65 Correct 9 ms 596 KB Output is correct
66 Correct 8 ms 680 KB Output is correct
67 Correct 7 ms 596 KB Output is correct
68 Correct 7 ms 596 KB Output is correct
69 Correct 13 ms 716 KB Output is correct
70 Correct 10 ms 724 KB Output is correct
71 Correct 10 ms 712 KB Output is correct
72 Correct 11 ms 704 KB Output is correct
73 Correct 9 ms 684 KB Output is correct
74 Correct 9 ms 704 KB Output is correct
75 Correct 8 ms 700 KB Output is correct
76 Correct 9 ms 596 KB Output is correct
77 Correct 25 ms 840 KB Output is correct
78 Correct 25 ms 828 KB Output is correct
79 Correct 21 ms 840 KB Output is correct
80 Correct 20 ms 780 KB Output is correct
81 Correct 19 ms 724 KB Output is correct
82 Correct 17 ms 724 KB Output is correct
83 Correct 17 ms 836 KB Output is correct
84 Correct 16 ms 824 KB Output is correct
85 Correct 39 ms 828 KB Output is correct
86 Correct 30 ms 792 KB Output is correct
87 Correct 30 ms 784 KB Output is correct
88 Correct 31 ms 724 KB Output is correct
89 Correct 25 ms 820 KB Output is correct
90 Correct 25 ms 724 KB Output is correct
91 Correct 24 ms 744 KB Output is correct
92 Correct 25 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 1 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 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 0 ms 596 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 0 ms 596 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 0 ms 492 KB Output is correct
33 Correct 0 ms 468 KB Output is correct
34 Correct 0 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 0 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 1 ms 468 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 0 ms 468 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 552 KB Output is correct
47 Correct 0 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 520 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 596 KB Output is correct
53 Correct 1 ms 596 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 1 ms 596 KB Output is correct
59 Correct 1 ms 596 KB Output is correct
60 Correct 1 ms 596 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 596 KB Output is correct
63 Correct 1 ms 596 KB Output is correct
64 Correct 1 ms 596 KB Output is correct
65 Correct 9 ms 596 KB Output is correct
66 Correct 8 ms 680 KB Output is correct
67 Correct 7 ms 596 KB Output is correct
68 Correct 7 ms 596 KB Output is correct
69 Correct 13 ms 716 KB Output is correct
70 Correct 10 ms 724 KB Output is correct
71 Correct 10 ms 712 KB Output is correct
72 Correct 11 ms 704 KB Output is correct
73 Correct 9 ms 684 KB Output is correct
74 Correct 9 ms 704 KB Output is correct
75 Correct 8 ms 700 KB Output is correct
76 Correct 9 ms 596 KB Output is correct
77 Correct 25 ms 840 KB Output is correct
78 Correct 25 ms 828 KB Output is correct
79 Correct 21 ms 840 KB Output is correct
80 Correct 20 ms 780 KB Output is correct
81 Correct 19 ms 724 KB Output is correct
82 Correct 17 ms 724 KB Output is correct
83 Correct 17 ms 836 KB Output is correct
84 Correct 16 ms 824 KB Output is correct
85 Correct 39 ms 828 KB Output is correct
86 Correct 30 ms 792 KB Output is correct
87 Correct 30 ms 784 KB Output is correct
88 Correct 31 ms 724 KB Output is correct
89 Correct 25 ms 820 KB Output is correct
90 Correct 25 ms 724 KB Output is correct
91 Correct 24 ms 744 KB Output is correct
92 Correct 25 ms 744 KB Output is correct
93 Correct 793 ms 2728 KB Output is correct
94 Correct 780 ms 2580 KB Output is correct
95 Correct 778 ms 2564 KB Output is correct
96 Correct 660 ms 2572 KB Output is correct
97 Correct 577 ms 2612 KB Output is correct
98 Correct 619 ms 2600 KB Output is correct
99 Correct 75 ms 1076 KB Output is correct
100 Correct 65 ms 1012 KB Output is correct
101 Correct 62 ms 1132 KB Output is correct
102 Correct 55 ms 1012 KB Output is correct
103 Correct 501 ms 1888 KB Output is correct
104 Correct 277 ms 1528 KB Output is correct
105 Correct 227 ms 1588 KB Output is correct
106 Correct 179 ms 1592 KB Output is correct
107 Correct 1487 ms 2560 KB Output is correct
108 Correct 635 ms 2544 KB Output is correct
109 Correct 518 ms 2512 KB Output is correct
110 Correct 464 ms 2520 KB Output is correct
111 Correct 50 ms 996 KB Output is correct
112 Correct 46 ms 980 KB Output is correct
113 Correct 44 ms 1024 KB Output is correct
114 Correct 114 ms 1040 KB Output is correct
115 Correct 87 ms 980 KB Output is correct
116 Correct 85 ms 1088 KB Output is correct
117 Correct 92 ms 1056 KB Output is correct
118 Correct 77 ms 1060 KB Output is correct
119 Correct 67 ms 1048 KB Output is correct
120 Correct 70 ms 1048 KB Output is correct
121 Correct 74 ms 1052 KB Output is correct
122 Correct 171 ms 1572 KB Output is correct
123 Correct 146 ms 1616 KB Output is correct
124 Correct 140 ms 1484 KB Output is correct
125 Correct 133 ms 1576 KB Output is correct
126 Correct 128 ms 1556 KB Output is correct
127 Correct 123 ms 1544 KB Output is correct
128 Correct 112 ms 1576 KB Output is correct
129 Correct 109 ms 1716 KB Output is correct
130 Correct 108 ms 1560 KB Output is correct
131 Correct 345 ms 1588 KB Output is correct
132 Correct 263 ms 1584 KB Output is correct
133 Correct 255 ms 1476 KB Output is correct
134 Correct 270 ms 1556 KB Output is correct
135 Correct 213 ms 1512 KB Output is correct
136 Correct 204 ms 1484 KB Output is correct
137 Correct 201 ms 1532 KB Output is correct
138 Correct 217 ms 1684 KB Output is correct
139 Correct 190 ms 1576 KB Output is correct
140 Correct 174 ms 1540 KB Output is correct
141 Correct 182 ms 1516 KB Output is correct
142 Correct 392 ms 2552 KB Output is correct
143 Correct 369 ms 2576 KB Output is correct
144 Correct 345 ms 2608 KB Output is correct
145 Correct 330 ms 2608 KB Output is correct
146 Correct 319 ms 2540 KB Output is correct
147 Correct 327 ms 2624 KB Output is correct
148 Correct 406 ms 2612 KB Output is correct
149 Correct 392 ms 2620 KB Output is correct
150 Correct 388 ms 2680 KB Output is correct
151 Correct 449 ms 2712 KB Output is correct
152 Correct 435 ms 2508 KB Output is correct
153 Correct 658 ms 2808 KB Output is correct
154 Correct 662 ms 2620 KB Output is correct
155 Correct 588 ms 2760 KB Output is correct
156 Correct 649 ms 2592 KB Output is correct
157 Correct 605 ms 2708 KB Output is correct
158 Correct 609 ms 2608 KB Output is correct
159 Correct 582 ms 2892 KB Output is correct
160 Correct 493 ms 2776 KB Output is correct
161 Correct 533 ms 2808 KB Output is correct
162 Correct 509 ms 2620 KB Output is correct
163 Correct 464 ms 2556 KB Output is correct
164 Correct 436 ms 2688 KB Output is correct
165 Correct 429 ms 2608 KB Output is correct
166 Correct 441 ms 2760 KB Output is correct
167 Correct 459 ms 2724 KB Output is correct