Submission #572970

# Submission time Handle Problem Language Result Execution time Memory
572970 2022-06-05T15:07:35 Z piOOE Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1512 ms 223208 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];

unordered_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 >> 1));
    return 0;
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:46:55: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   46 |                     int newb = b & (1 << n) - (1 << i + 1);
      |                                                     ~~^~~
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;
      |                                   ~~~~~~~~~~~~~^~~
amusementpark.cpp:53:49: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |     cout << mul(dp[(1 << n) - 1][0], mul(m, MOD + 1 >> 1));
      |                                             ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14672 KB Output is correct
2 Correct 8 ms 14676 KB Output is correct
3 Correct 7 ms 14676 KB Output is correct
4 Correct 8 ms 14636 KB Output is correct
5 Correct 9 ms 14676 KB Output is correct
6 Correct 8 ms 14676 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 8 ms 14676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14672 KB Output is correct
2 Correct 8 ms 14676 KB Output is correct
3 Correct 7 ms 14676 KB Output is correct
4 Correct 8 ms 14636 KB Output is correct
5 Correct 9 ms 14676 KB Output is correct
6 Correct 8 ms 14676 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 8 ms 14676 KB Output is correct
9 Correct 8 ms 14676 KB Output is correct
10 Correct 9 ms 14688 KB Output is correct
11 Correct 8 ms 14676 KB Output is correct
12 Correct 10 ms 14648 KB Output is correct
13 Correct 8 ms 14604 KB Output is correct
14 Correct 8 ms 14676 KB Output is correct
15 Correct 8 ms 14688 KB Output is correct
16 Correct 8 ms 14668 KB Output is correct
17 Correct 8 ms 14676 KB Output is correct
18 Correct 8 ms 14676 KB Output is correct
19 Correct 8 ms 14676 KB Output is correct
20 Correct 9 ms 14676 KB Output is correct
21 Correct 8 ms 14676 KB Output is correct
22 Correct 8 ms 14676 KB Output is correct
23 Correct 8 ms 14676 KB Output is correct
24 Correct 8 ms 14676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14672 KB Output is correct
2 Correct 8 ms 14676 KB Output is correct
3 Correct 7 ms 14676 KB Output is correct
4 Correct 8 ms 14636 KB Output is correct
5 Correct 9 ms 14676 KB Output is correct
6 Correct 8 ms 14676 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 8 ms 14676 KB Output is correct
9 Correct 8 ms 14676 KB Output is correct
10 Correct 9 ms 14688 KB Output is correct
11 Correct 8 ms 14676 KB Output is correct
12 Correct 10 ms 14648 KB Output is correct
13 Correct 8 ms 14604 KB Output is correct
14 Correct 8 ms 14676 KB Output is correct
15 Correct 8 ms 14688 KB Output is correct
16 Correct 8 ms 14668 KB Output is correct
17 Correct 8 ms 14676 KB Output is correct
18 Correct 8 ms 14676 KB Output is correct
19 Correct 8 ms 14676 KB Output is correct
20 Correct 9 ms 14676 KB Output is correct
21 Correct 8 ms 14676 KB Output is correct
22 Correct 8 ms 14676 KB Output is correct
23 Correct 8 ms 14676 KB Output is correct
24 Correct 8 ms 14676 KB Output is correct
25 Correct 9 ms 14704 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 9 ms 14676 KB Output is correct
28 Correct 8 ms 14676 KB Output is correct
29 Correct 9 ms 14676 KB Output is correct
30 Correct 8 ms 14612 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 8 ms 14676 KB Output is correct
33 Correct 8 ms 14676 KB Output is correct
34 Correct 9 ms 14676 KB Output is correct
35 Correct 9 ms 14676 KB Output is correct
36 Correct 9 ms 14740 KB Output is correct
37 Correct 8 ms 14676 KB Output is correct
38 Correct 8 ms 14676 KB Output is correct
39 Correct 8 ms 14676 KB Output is correct
40 Correct 8 ms 14748 KB Output is correct
41 Correct 8 ms 14676 KB Output is correct
42 Correct 8 ms 14676 KB Output is correct
43 Correct 9 ms 14680 KB Output is correct
44 Correct 11 ms 14780 KB Output is correct
45 Correct 8 ms 14676 KB Output is correct
46 Correct 8 ms 14756 KB Output is correct
47 Correct 9 ms 14696 KB Output is correct
48 Correct 8 ms 14676 KB Output is correct
49 Correct 8 ms 14676 KB Output is correct
50 Correct 8 ms 14676 KB Output is correct
51 Correct 8 ms 14768 KB Output is correct
52 Correct 8 ms 14804 KB Output is correct
53 Correct 9 ms 14804 KB Output is correct
54 Correct 8 ms 14804 KB Output is correct
55 Correct 9 ms 14776 KB Output is correct
56 Correct 9 ms 14844 KB Output is correct
57 Correct 9 ms 14868 KB Output is correct
58 Correct 8 ms 14804 KB Output is correct
59 Correct 8 ms 14804 KB Output is correct
60 Correct 8 ms 14804 KB Output is correct
61 Correct 8 ms 14860 KB Output is correct
62 Correct 9 ms 14804 KB Output is correct
63 Correct 10 ms 14828 KB Output is correct
64 Correct 9 ms 14860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14672 KB Output is correct
2 Correct 8 ms 14676 KB Output is correct
3 Correct 7 ms 14676 KB Output is correct
4 Correct 8 ms 14636 KB Output is correct
5 Correct 9 ms 14676 KB Output is correct
6 Correct 8 ms 14676 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 8 ms 14676 KB Output is correct
9 Correct 8 ms 14676 KB Output is correct
10 Correct 9 ms 14688 KB Output is correct
11 Correct 8 ms 14676 KB Output is correct
12 Correct 10 ms 14648 KB Output is correct
13 Correct 8 ms 14604 KB Output is correct
14 Correct 8 ms 14676 KB Output is correct
15 Correct 8 ms 14688 KB Output is correct
16 Correct 8 ms 14668 KB Output is correct
17 Correct 8 ms 14676 KB Output is correct
18 Correct 8 ms 14676 KB Output is correct
19 Correct 8 ms 14676 KB Output is correct
20 Correct 9 ms 14676 KB Output is correct
21 Correct 8 ms 14676 KB Output is correct
22 Correct 8 ms 14676 KB Output is correct
23 Correct 8 ms 14676 KB Output is correct
24 Correct 8 ms 14676 KB Output is correct
25 Correct 9 ms 14704 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 9 ms 14676 KB Output is correct
28 Correct 8 ms 14676 KB Output is correct
29 Correct 9 ms 14676 KB Output is correct
30 Correct 8 ms 14612 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 8 ms 14676 KB Output is correct
33 Correct 8 ms 14676 KB Output is correct
34 Correct 9 ms 14676 KB Output is correct
35 Correct 9 ms 14676 KB Output is correct
36 Correct 9 ms 14740 KB Output is correct
37 Correct 8 ms 14676 KB Output is correct
38 Correct 8 ms 14676 KB Output is correct
39 Correct 8 ms 14676 KB Output is correct
40 Correct 8 ms 14748 KB Output is correct
41 Correct 8 ms 14676 KB Output is correct
42 Correct 8 ms 14676 KB Output is correct
43 Correct 9 ms 14680 KB Output is correct
44 Correct 11 ms 14780 KB Output is correct
45 Correct 8 ms 14676 KB Output is correct
46 Correct 8 ms 14756 KB Output is correct
47 Correct 9 ms 14696 KB Output is correct
48 Correct 8 ms 14676 KB Output is correct
49 Correct 8 ms 14676 KB Output is correct
50 Correct 8 ms 14676 KB Output is correct
51 Correct 8 ms 14768 KB Output is correct
52 Correct 8 ms 14804 KB Output is correct
53 Correct 9 ms 14804 KB Output is correct
54 Correct 8 ms 14804 KB Output is correct
55 Correct 9 ms 14776 KB Output is correct
56 Correct 9 ms 14844 KB Output is correct
57 Correct 9 ms 14868 KB Output is correct
58 Correct 8 ms 14804 KB Output is correct
59 Correct 8 ms 14804 KB Output is correct
60 Correct 8 ms 14804 KB Output is correct
61 Correct 8 ms 14860 KB Output is correct
62 Correct 9 ms 14804 KB Output is correct
63 Correct 10 ms 14828 KB Output is correct
64 Correct 9 ms 14860 KB Output is correct
65 Correct 31 ms 19596 KB Output is correct
66 Correct 37 ms 20700 KB Output is correct
67 Correct 39 ms 20296 KB Output is correct
68 Correct 39 ms 19988 KB Output is correct
69 Correct 19 ms 17728 KB Output is correct
70 Correct 20 ms 17992 KB Output is correct
71 Correct 20 ms 17984 KB Output is correct
72 Correct 20 ms 18052 KB Output is correct
73 Correct 22 ms 18104 KB Output is correct
74 Correct 21 ms 18112 KB Output is correct
75 Correct 22 ms 18088 KB Output is correct
76 Correct 21 ms 18116 KB Output is correct
77 Correct 63 ms 26184 KB Output is correct
78 Correct 71 ms 27100 KB Output is correct
79 Correct 102 ms 29884 KB Output is correct
80 Correct 84 ms 27152 KB Output is correct
81 Correct 88 ms 28292 KB Output is correct
82 Correct 81 ms 26908 KB Output is correct
83 Correct 83 ms 26536 KB Output is correct
84 Correct 61 ms 24052 KB Output is correct
85 Correct 32 ms 20940 KB Output is correct
86 Correct 34 ms 21588 KB Output is correct
87 Correct 33 ms 21572 KB Output is correct
88 Correct 33 ms 21608 KB Output is correct
89 Correct 37 ms 21752 KB Output is correct
90 Correct 36 ms 21716 KB Output is correct
91 Correct 35 ms 21708 KB Output is correct
92 Correct 39 ms 21756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14672 KB Output is correct
2 Correct 8 ms 14676 KB Output is correct
3 Correct 7 ms 14676 KB Output is correct
4 Correct 8 ms 14636 KB Output is correct
5 Correct 9 ms 14676 KB Output is correct
6 Correct 8 ms 14676 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 8 ms 14676 KB Output is correct
9 Correct 8 ms 14676 KB Output is correct
10 Correct 9 ms 14688 KB Output is correct
11 Correct 8 ms 14676 KB Output is correct
12 Correct 10 ms 14648 KB Output is correct
13 Correct 8 ms 14604 KB Output is correct
14 Correct 8 ms 14676 KB Output is correct
15 Correct 8 ms 14688 KB Output is correct
16 Correct 8 ms 14668 KB Output is correct
17 Correct 8 ms 14676 KB Output is correct
18 Correct 8 ms 14676 KB Output is correct
19 Correct 8 ms 14676 KB Output is correct
20 Correct 9 ms 14676 KB Output is correct
21 Correct 8 ms 14676 KB Output is correct
22 Correct 8 ms 14676 KB Output is correct
23 Correct 8 ms 14676 KB Output is correct
24 Correct 8 ms 14676 KB Output is correct
25 Correct 9 ms 14704 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 9 ms 14676 KB Output is correct
28 Correct 8 ms 14676 KB Output is correct
29 Correct 9 ms 14676 KB Output is correct
30 Correct 8 ms 14612 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 8 ms 14676 KB Output is correct
33 Correct 8 ms 14676 KB Output is correct
34 Correct 9 ms 14676 KB Output is correct
35 Correct 9 ms 14676 KB Output is correct
36 Correct 9 ms 14740 KB Output is correct
37 Correct 8 ms 14676 KB Output is correct
38 Correct 8 ms 14676 KB Output is correct
39 Correct 8 ms 14676 KB Output is correct
40 Correct 8 ms 14748 KB Output is correct
41 Correct 8 ms 14676 KB Output is correct
42 Correct 8 ms 14676 KB Output is correct
43 Correct 9 ms 14680 KB Output is correct
44 Correct 11 ms 14780 KB Output is correct
45 Correct 8 ms 14676 KB Output is correct
46 Correct 8 ms 14756 KB Output is correct
47 Correct 9 ms 14696 KB Output is correct
48 Correct 8 ms 14676 KB Output is correct
49 Correct 8 ms 14676 KB Output is correct
50 Correct 8 ms 14676 KB Output is correct
51 Correct 8 ms 14768 KB Output is correct
52 Correct 8 ms 14804 KB Output is correct
53 Correct 9 ms 14804 KB Output is correct
54 Correct 8 ms 14804 KB Output is correct
55 Correct 9 ms 14776 KB Output is correct
56 Correct 9 ms 14844 KB Output is correct
57 Correct 9 ms 14868 KB Output is correct
58 Correct 8 ms 14804 KB Output is correct
59 Correct 8 ms 14804 KB Output is correct
60 Correct 8 ms 14804 KB Output is correct
61 Correct 8 ms 14860 KB Output is correct
62 Correct 9 ms 14804 KB Output is correct
63 Correct 10 ms 14828 KB Output is correct
64 Correct 9 ms 14860 KB Output is correct
65 Correct 31 ms 19596 KB Output is correct
66 Correct 37 ms 20700 KB Output is correct
67 Correct 39 ms 20296 KB Output is correct
68 Correct 39 ms 19988 KB Output is correct
69 Correct 19 ms 17728 KB Output is correct
70 Correct 20 ms 17992 KB Output is correct
71 Correct 20 ms 17984 KB Output is correct
72 Correct 20 ms 18052 KB Output is correct
73 Correct 22 ms 18104 KB Output is correct
74 Correct 21 ms 18112 KB Output is correct
75 Correct 22 ms 18088 KB Output is correct
76 Correct 21 ms 18116 KB Output is correct
77 Correct 63 ms 26184 KB Output is correct
78 Correct 71 ms 27100 KB Output is correct
79 Correct 102 ms 29884 KB Output is correct
80 Correct 84 ms 27152 KB Output is correct
81 Correct 88 ms 28292 KB Output is correct
82 Correct 81 ms 26908 KB Output is correct
83 Correct 83 ms 26536 KB Output is correct
84 Correct 61 ms 24052 KB Output is correct
85 Correct 32 ms 20940 KB Output is correct
86 Correct 34 ms 21588 KB Output is correct
87 Correct 33 ms 21572 KB Output is correct
88 Correct 33 ms 21608 KB Output is correct
89 Correct 37 ms 21752 KB Output is correct
90 Correct 36 ms 21716 KB Output is correct
91 Correct 35 ms 21708 KB Output is correct
92 Correct 39 ms 21756 KB Output is correct
93 Correct 332 ms 74648 KB Output is correct
94 Correct 165 ms 56544 KB Output is correct
95 Correct 96 ms 52556 KB Output is correct
96 Correct 360 ms 76724 KB Output is correct
97 Correct 356 ms 76236 KB Output is correct
98 Correct 329 ms 74140 KB Output is correct
99 Correct 92 ms 33400 KB Output is correct
100 Correct 154 ms 40944 KB Output is correct
101 Correct 210 ms 47596 KB Output is correct
102 Correct 223 ms 49388 KB Output is correct
103 Correct 44 ms 33068 KB Output is correct
104 Correct 48 ms 33468 KB Output is correct
105 Correct 113 ms 41164 KB Output is correct
106 Correct 324 ms 68780 KB Output is correct
107 Correct 77 ms 51484 KB Output is correct
108 Correct 197 ms 71344 KB Output is correct
109 Correct 723 ms 131776 KB Output is correct
110 Correct 1512 ms 223208 KB Output is correct
111 Correct 230 ms 48952 KB Output is correct
112 Correct 197 ms 42280 KB Output is correct
113 Correct 189 ms 40772 KB Output is correct
114 Correct 59 ms 27468 KB Output is correct
115 Correct 71 ms 28804 KB Output is correct
116 Correct 72 ms 28876 KB Output is correct
117 Correct 67 ms 28896 KB Output is correct
118 Correct 75 ms 29240 KB Output is correct
119 Correct 76 ms 29212 KB Output is correct
120 Correct 76 ms 29244 KB Output is correct
121 Correct 74 ms 29280 KB Output is correct
122 Correct 393 ms 74276 KB Output is correct
123 Correct 569 ms 92748 KB Output is correct
124 Correct 553 ms 87952 KB Output is correct
125 Correct 511 ms 81660 KB Output is correct
126 Correct 504 ms 73344 KB Output is correct
127 Correct 319 ms 57036 KB Output is correct
128 Correct 220 ms 46920 KB Output is correct
129 Correct 148 ms 40012 KB Output is correct
130 Correct 74 ms 33128 KB Output is correct
131 Correct 126 ms 40728 KB Output is correct
132 Correct 151 ms 43852 KB Output is correct
133 Correct 151 ms 43900 KB Output is correct
134 Correct 143 ms 43856 KB Output is correct
135 Correct 166 ms 44732 KB Output is correct
136 Correct 162 ms 44776 KB Output is correct
137 Correct 164 ms 44804 KB Output is correct
138 Correct 159 ms 44776 KB Output is correct
139 Correct 167 ms 44676 KB Output is correct
140 Correct 161 ms 44680 KB Output is correct
141 Correct 164 ms 44560 KB Output is correct
142 Correct 1348 ms 187804 KB Output is correct
143 Correct 1327 ms 174904 KB Output is correct
144 Correct 961 ms 130568 KB Output is correct
145 Correct 739 ms 103312 KB Output is correct
146 Correct 427 ms 73936 KB Output is correct
147 Correct 166 ms 51596 KB Output is correct
148 Correct 1297 ms 178540 KB Output is correct
149 Correct 1275 ms 174476 KB Output is correct
150 Correct 1468 ms 196520 KB Output is correct
151 Correct 310 ms 75324 KB Output is correct
152 Correct 318 ms 77388 KB Output is correct
153 Correct 368 ms 76652 KB Output is correct
154 Correct 359 ms 76736 KB Output is correct
155 Correct 356 ms 76732 KB Output is correct
156 Correct 347 ms 76700 KB Output is correct
157 Correct 365 ms 76676 KB Output is correct
158 Correct 362 ms 76616 KB Output is correct
159 Correct 375 ms 76544 KB Output is correct
160 Correct 378 ms 76580 KB Output is correct
161 Correct 366 ms 76572 KB Output is correct
162 Correct 364 ms 75368 KB Output is correct
163 Correct 365 ms 75392 KB Output is correct
164 Correct 377 ms 75400 KB Output is correct
165 Correct 369 ms 75452 KB Output is correct
166 Correct 372 ms 75520 KB Output is correct
167 Correct 363 ms 75420 KB Output is correct