Submission #572967

# Submission time Handle Problem Language Result Execution time Memory
572967 2022-06-05T15:06:30 Z piOOE Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1719 ms 234860 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 adj[N];

map<int, int> dp[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);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        adj[a] |= (1 << b);
        adj[b] |= (1 << a);
    }
    dp[0][(1 << n) - 1] = 1;
    for (int a = 0; a < (1 << n); ++a) {
        for (auto [b, cnt] : dp[a]) {
            for (int i = 0; i < n; ++i) {
                if (b & 1 << i) {
                    int newb = b & (1 << n) - (1 << (i + 1));
                    newb = newb | (adj[i] | a) ^ a;
                    dp[a ^ 1 << i][newb] = add(dp[a ^ 1 << i][newb], cnt);
                }
            }
        }
    }
    cout << mul(dp[(1 << n) - 1][0], mul(m, (MOD + 1) / 2));
    return 0;
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:46:45: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   46 |                     int newb = b & (1 << n) - (1 << (i + 1));
      |                                    ~~~~~~~~~^~~~~~~~~~~~~~~~
amusementpark.cpp:47:48: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   47 |                     newb = newb | (adj[i] | a) ^ a;
      |                                   ~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12628 KB Output is correct
2 Correct 6 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 6 ms 12628 KB Output is correct
5 Correct 8 ms 12624 KB Output is correct
6 Correct 6 ms 12632 KB Output is correct
7 Correct 7 ms 12636 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12628 KB Output is correct
2 Correct 6 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 6 ms 12628 KB Output is correct
5 Correct 8 ms 12624 KB Output is correct
6 Correct 6 ms 12632 KB Output is correct
7 Correct 7 ms 12636 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
9 Correct 6 ms 12628 KB Output is correct
10 Correct 6 ms 12628 KB Output is correct
11 Correct 7 ms 12628 KB Output is correct
12 Correct 6 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 6 ms 12628 KB Output is correct
15 Correct 6 ms 12628 KB Output is correct
16 Correct 6 ms 12632 KB Output is correct
17 Correct 8 ms 12560 KB Output is correct
18 Correct 7 ms 12628 KB Output is correct
19 Correct 6 ms 12628 KB Output is correct
20 Correct 6 ms 12628 KB Output is correct
21 Correct 6 ms 12628 KB Output is correct
22 Correct 8 ms 12628 KB Output is correct
23 Correct 6 ms 12628 KB Output is correct
24 Correct 7 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12628 KB Output is correct
2 Correct 6 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 6 ms 12628 KB Output is correct
5 Correct 8 ms 12624 KB Output is correct
6 Correct 6 ms 12632 KB Output is correct
7 Correct 7 ms 12636 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
9 Correct 6 ms 12628 KB Output is correct
10 Correct 6 ms 12628 KB Output is correct
11 Correct 7 ms 12628 KB Output is correct
12 Correct 6 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 6 ms 12628 KB Output is correct
15 Correct 6 ms 12628 KB Output is correct
16 Correct 6 ms 12632 KB Output is correct
17 Correct 8 ms 12560 KB Output is correct
18 Correct 7 ms 12628 KB Output is correct
19 Correct 6 ms 12628 KB Output is correct
20 Correct 6 ms 12628 KB Output is correct
21 Correct 6 ms 12628 KB Output is correct
22 Correct 8 ms 12628 KB Output is correct
23 Correct 6 ms 12628 KB Output is correct
24 Correct 7 ms 12628 KB Output is correct
25 Correct 6 ms 12628 KB Output is correct
26 Correct 9 ms 12516 KB Output is correct
27 Correct 7 ms 12628 KB Output is correct
28 Correct 6 ms 12608 KB Output is correct
29 Correct 6 ms 12628 KB Output is correct
30 Correct 6 ms 12628 KB Output is correct
31 Correct 6 ms 12628 KB Output is correct
32 Correct 6 ms 12656 KB Output is correct
33 Correct 6 ms 12600 KB Output is correct
34 Correct 7 ms 12628 KB Output is correct
35 Correct 7 ms 12628 KB Output is correct
36 Correct 6 ms 12628 KB Output is correct
37 Correct 7 ms 12628 KB Output is correct
38 Correct 6 ms 12640 KB Output is correct
39 Correct 7 ms 12628 KB Output is correct
40 Correct 7 ms 12640 KB Output is correct
41 Correct 7 ms 12628 KB Output is correct
42 Correct 6 ms 12628 KB Output is correct
43 Correct 8 ms 12628 KB Output is correct
44 Correct 7 ms 12628 KB Output is correct
45 Correct 7 ms 12628 KB Output is correct
46 Correct 7 ms 12628 KB Output is correct
47 Correct 7 ms 12580 KB Output is correct
48 Correct 7 ms 12628 KB Output is correct
49 Correct 7 ms 12628 KB Output is correct
50 Correct 6 ms 12628 KB Output is correct
51 Correct 7 ms 12628 KB Output is correct
52 Correct 7 ms 12616 KB Output is correct
53 Correct 7 ms 12716 KB Output is correct
54 Correct 7 ms 12756 KB Output is correct
55 Correct 7 ms 12628 KB Output is correct
56 Correct 7 ms 12756 KB Output is correct
57 Correct 7 ms 12756 KB Output is correct
58 Correct 7 ms 12640 KB Output is correct
59 Correct 7 ms 12628 KB Output is correct
60 Correct 7 ms 12676 KB Output is correct
61 Correct 7 ms 12628 KB Output is correct
62 Correct 7 ms 12628 KB Output is correct
63 Correct 7 ms 12748 KB Output is correct
64 Correct 7 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12628 KB Output is correct
2 Correct 6 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 6 ms 12628 KB Output is correct
5 Correct 8 ms 12624 KB Output is correct
6 Correct 6 ms 12632 KB Output is correct
7 Correct 7 ms 12636 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
9 Correct 6 ms 12628 KB Output is correct
10 Correct 6 ms 12628 KB Output is correct
11 Correct 7 ms 12628 KB Output is correct
12 Correct 6 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 6 ms 12628 KB Output is correct
15 Correct 6 ms 12628 KB Output is correct
16 Correct 6 ms 12632 KB Output is correct
17 Correct 8 ms 12560 KB Output is correct
18 Correct 7 ms 12628 KB Output is correct
19 Correct 6 ms 12628 KB Output is correct
20 Correct 6 ms 12628 KB Output is correct
21 Correct 6 ms 12628 KB Output is correct
22 Correct 8 ms 12628 KB Output is correct
23 Correct 6 ms 12628 KB Output is correct
24 Correct 7 ms 12628 KB Output is correct
25 Correct 6 ms 12628 KB Output is correct
26 Correct 9 ms 12516 KB Output is correct
27 Correct 7 ms 12628 KB Output is correct
28 Correct 6 ms 12608 KB Output is correct
29 Correct 6 ms 12628 KB Output is correct
30 Correct 6 ms 12628 KB Output is correct
31 Correct 6 ms 12628 KB Output is correct
32 Correct 6 ms 12656 KB Output is correct
33 Correct 6 ms 12600 KB Output is correct
34 Correct 7 ms 12628 KB Output is correct
35 Correct 7 ms 12628 KB Output is correct
36 Correct 6 ms 12628 KB Output is correct
37 Correct 7 ms 12628 KB Output is correct
38 Correct 6 ms 12640 KB Output is correct
39 Correct 7 ms 12628 KB Output is correct
40 Correct 7 ms 12640 KB Output is correct
41 Correct 7 ms 12628 KB Output is correct
42 Correct 6 ms 12628 KB Output is correct
43 Correct 8 ms 12628 KB Output is correct
44 Correct 7 ms 12628 KB Output is correct
45 Correct 7 ms 12628 KB Output is correct
46 Correct 7 ms 12628 KB Output is correct
47 Correct 7 ms 12580 KB Output is correct
48 Correct 7 ms 12628 KB Output is correct
49 Correct 7 ms 12628 KB Output is correct
50 Correct 6 ms 12628 KB Output is correct
51 Correct 7 ms 12628 KB Output is correct
52 Correct 7 ms 12616 KB Output is correct
53 Correct 7 ms 12716 KB Output is correct
54 Correct 7 ms 12756 KB Output is correct
55 Correct 7 ms 12628 KB Output is correct
56 Correct 7 ms 12756 KB Output is correct
57 Correct 7 ms 12756 KB Output is correct
58 Correct 7 ms 12640 KB Output is correct
59 Correct 7 ms 12628 KB Output is correct
60 Correct 7 ms 12676 KB Output is correct
61 Correct 7 ms 12628 KB Output is correct
62 Correct 7 ms 12628 KB Output is correct
63 Correct 7 ms 12748 KB Output is correct
64 Correct 7 ms 12628 KB Output is correct
65 Correct 27 ms 17228 KB Output is correct
66 Correct 38 ms 18804 KB Output is correct
67 Correct 34 ms 18160 KB Output is correct
68 Correct 33 ms 17904 KB Output is correct
69 Correct 12 ms 14548 KB Output is correct
70 Correct 13 ms 14932 KB Output is correct
71 Correct 15 ms 14932 KB Output is correct
72 Correct 14 ms 14908 KB Output is correct
73 Correct 14 ms 15060 KB Output is correct
74 Correct 16 ms 15060 KB Output is correct
75 Correct 18 ms 15068 KB Output is correct
76 Correct 17 ms 15024 KB Output is correct
77 Correct 59 ms 23808 KB Output is correct
78 Correct 66 ms 25072 KB Output is correct
79 Correct 92 ms 28108 KB Output is correct
80 Correct 75 ms 25396 KB Output is correct
81 Correct 88 ms 26720 KB Output is correct
82 Correct 77 ms 25292 KB Output is correct
83 Correct 75 ms 24864 KB Output is correct
84 Correct 50 ms 21284 KB Output is correct
85 Correct 18 ms 16668 KB Output is correct
86 Correct 23 ms 17592 KB Output is correct
87 Correct 22 ms 17620 KB Output is correct
88 Correct 24 ms 17636 KB Output is correct
89 Correct 24 ms 17780 KB Output is correct
90 Correct 24 ms 17820 KB Output is correct
91 Correct 25 ms 17812 KB Output is correct
92 Correct 23 ms 17808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12628 KB Output is correct
2 Correct 6 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 6 ms 12628 KB Output is correct
5 Correct 8 ms 12624 KB Output is correct
6 Correct 6 ms 12632 KB Output is correct
7 Correct 7 ms 12636 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
9 Correct 6 ms 12628 KB Output is correct
10 Correct 6 ms 12628 KB Output is correct
11 Correct 7 ms 12628 KB Output is correct
12 Correct 6 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 6 ms 12628 KB Output is correct
15 Correct 6 ms 12628 KB Output is correct
16 Correct 6 ms 12632 KB Output is correct
17 Correct 8 ms 12560 KB Output is correct
18 Correct 7 ms 12628 KB Output is correct
19 Correct 6 ms 12628 KB Output is correct
20 Correct 6 ms 12628 KB Output is correct
21 Correct 6 ms 12628 KB Output is correct
22 Correct 8 ms 12628 KB Output is correct
23 Correct 6 ms 12628 KB Output is correct
24 Correct 7 ms 12628 KB Output is correct
25 Correct 6 ms 12628 KB Output is correct
26 Correct 9 ms 12516 KB Output is correct
27 Correct 7 ms 12628 KB Output is correct
28 Correct 6 ms 12608 KB Output is correct
29 Correct 6 ms 12628 KB Output is correct
30 Correct 6 ms 12628 KB Output is correct
31 Correct 6 ms 12628 KB Output is correct
32 Correct 6 ms 12656 KB Output is correct
33 Correct 6 ms 12600 KB Output is correct
34 Correct 7 ms 12628 KB Output is correct
35 Correct 7 ms 12628 KB Output is correct
36 Correct 6 ms 12628 KB Output is correct
37 Correct 7 ms 12628 KB Output is correct
38 Correct 6 ms 12640 KB Output is correct
39 Correct 7 ms 12628 KB Output is correct
40 Correct 7 ms 12640 KB Output is correct
41 Correct 7 ms 12628 KB Output is correct
42 Correct 6 ms 12628 KB Output is correct
43 Correct 8 ms 12628 KB Output is correct
44 Correct 7 ms 12628 KB Output is correct
45 Correct 7 ms 12628 KB Output is correct
46 Correct 7 ms 12628 KB Output is correct
47 Correct 7 ms 12580 KB Output is correct
48 Correct 7 ms 12628 KB Output is correct
49 Correct 7 ms 12628 KB Output is correct
50 Correct 6 ms 12628 KB Output is correct
51 Correct 7 ms 12628 KB Output is correct
52 Correct 7 ms 12616 KB Output is correct
53 Correct 7 ms 12716 KB Output is correct
54 Correct 7 ms 12756 KB Output is correct
55 Correct 7 ms 12628 KB Output is correct
56 Correct 7 ms 12756 KB Output is correct
57 Correct 7 ms 12756 KB Output is correct
58 Correct 7 ms 12640 KB Output is correct
59 Correct 7 ms 12628 KB Output is correct
60 Correct 7 ms 12676 KB Output is correct
61 Correct 7 ms 12628 KB Output is correct
62 Correct 7 ms 12628 KB Output is correct
63 Correct 7 ms 12748 KB Output is correct
64 Correct 7 ms 12628 KB Output is correct
65 Correct 27 ms 17228 KB Output is correct
66 Correct 38 ms 18804 KB Output is correct
67 Correct 34 ms 18160 KB Output is correct
68 Correct 33 ms 17904 KB Output is correct
69 Correct 12 ms 14548 KB Output is correct
70 Correct 13 ms 14932 KB Output is correct
71 Correct 15 ms 14932 KB Output is correct
72 Correct 14 ms 14908 KB Output is correct
73 Correct 14 ms 15060 KB Output is correct
74 Correct 16 ms 15060 KB Output is correct
75 Correct 18 ms 15068 KB Output is correct
76 Correct 17 ms 15024 KB Output is correct
77 Correct 59 ms 23808 KB Output is correct
78 Correct 66 ms 25072 KB Output is correct
79 Correct 92 ms 28108 KB Output is correct
80 Correct 75 ms 25396 KB Output is correct
81 Correct 88 ms 26720 KB Output is correct
82 Correct 77 ms 25292 KB Output is correct
83 Correct 75 ms 24864 KB Output is correct
84 Correct 50 ms 21284 KB Output is correct
85 Correct 18 ms 16668 KB Output is correct
86 Correct 23 ms 17592 KB Output is correct
87 Correct 22 ms 17620 KB Output is correct
88 Correct 24 ms 17636 KB Output is correct
89 Correct 24 ms 17780 KB Output is correct
90 Correct 24 ms 17820 KB Output is correct
91 Correct 25 ms 17812 KB Output is correct
92 Correct 23 ms 17808 KB Output is correct
93 Correct 196 ms 59500 KB Output is correct
94 Correct 79 ms 32360 KB Output is correct
95 Correct 44 ms 26508 KB Output is correct
96 Correct 227 ms 62612 KB Output is correct
97 Correct 208 ms 61956 KB Output is correct
98 Correct 191 ms 58648 KB Output is correct
99 Correct 80 ms 29372 KB Output is correct
100 Correct 139 ms 38904 KB Output is correct
101 Correct 206 ms 46820 KB Output is correct
102 Correct 223 ms 48644 KB Output is correct
103 Correct 20 ms 18772 KB Output is correct
104 Correct 20 ms 19252 KB Output is correct
105 Correct 62 ms 30772 KB Output is correct
106 Correct 301 ms 66408 KB Output is correct
107 Correct 29 ms 24916 KB Output is correct
108 Correct 132 ms 54504 KB Output is correct
109 Correct 664 ms 130992 KB Output is correct
110 Correct 1567 ms 234860 KB Output is correct
111 Correct 222 ms 48416 KB Output is correct
112 Correct 181 ms 41644 KB Output is correct
113 Correct 175 ms 40020 KB Output is correct
114 Correct 34 ms 21072 KB Output is correct
115 Correct 41 ms 23092 KB Output is correct
116 Correct 41 ms 23124 KB Output is correct
117 Correct 45 ms 23108 KB Output is correct
118 Correct 53 ms 23672 KB Output is correct
119 Correct 54 ms 23772 KB Output is correct
120 Correct 44 ms 23756 KB Output is correct
121 Correct 42 ms 23772 KB Output is correct
122 Correct 358 ms 73212 KB Output is correct
123 Correct 552 ms 95052 KB Output is correct
124 Correct 508 ms 90068 KB Output is correct
125 Correct 485 ms 83056 KB Output is correct
126 Correct 424 ms 74748 KB Output is correct
127 Correct 261 ms 54352 KB Output is correct
128 Correct 153 ms 39404 KB Output is correct
129 Correct 87 ms 29220 KB Output is correct
130 Correct 28 ms 18756 KB Output is correct
131 Correct 67 ms 30284 KB Output is correct
132 Correct 87 ms 34860 KB Output is correct
133 Correct 88 ms 34856 KB Output is correct
134 Correct 84 ms 34844 KB Output is correct
135 Correct 112 ms 36176 KB Output is correct
136 Correct 102 ms 36300 KB Output is correct
137 Correct 93 ms 36236 KB Output is correct
138 Correct 87 ms 36196 KB Output is correct
139 Correct 99 ms 35964 KB Output is correct
140 Correct 104 ms 36032 KB Output is correct
141 Correct 89 ms 36044 KB Output is correct
142 Correct 1260 ms 196692 KB Output is correct
143 Correct 1213 ms 182704 KB Output is correct
144 Correct 901 ms 135084 KB Output is correct
145 Correct 644 ms 101420 KB Output is correct
146 Correct 350 ms 58444 KB Output is correct
147 Correct 72 ms 24920 KB Output is correct
148 Correct 1437 ms 186292 KB Output is correct
149 Correct 1355 ms 181916 KB Output is correct
150 Correct 1719 ms 206712 KB Output is correct
151 Correct 222 ms 60488 KB Output is correct
152 Correct 264 ms 63592 KB Output is correct
153 Correct 217 ms 62628 KB Output is correct
154 Correct 218 ms 62628 KB Output is correct
155 Correct 248 ms 62528 KB Output is correct
156 Correct 212 ms 62572 KB Output is correct
157 Correct 220 ms 62572 KB Output is correct
158 Correct 222 ms 62608 KB Output is correct
159 Correct 232 ms 62352 KB Output is correct
160 Correct 223 ms 62408 KB Output is correct
161 Correct 199 ms 62416 KB Output is correct
162 Correct 220 ms 60640 KB Output is correct
163 Correct 240 ms 60620 KB Output is correct
164 Correct 224 ms 60632 KB Output is correct
165 Correct 213 ms 60620 KB Output is correct
166 Correct 195 ms 60700 KB Output is correct
167 Correct 186 ms 60620 KB Output is correct