Submission #1107427

# Submission time Handle Problem Language Result Execution time Memory
1107427 2024-11-01T08:25:03 Z otarius Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1609 ms 3784 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

// #define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

void open_file(string filename) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
// const int maxN;

ll dp[1 << 18];
int popc[1 << 18];
bool g[20][20], good[1 << 18];
ll binpow(ll a, ll b) {
    a %= mod;
    if (!b) return 1;
    if (b & 1) return a * binpow(a, b - 1) % mod;
    return binpow(a * a, b >> 1);
}
ll inv(ll x) {
    return binpow(x, mod - 2);
}
void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int x, y; cin >> x >> y;
        x--; y--; g[x][y] = g[y][x] = 1;
    } for (int i = 0; i < (1 << n); i++) good[i] = 1;
    for (int msk = 0; msk < (1 << n); msk++) {
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (!(msk & (1 << i))) continue;
                if (!(msk & (1 << j))) continue;
                if (g[i][j]) good[msk] = 0;
            }
        }
    } dp[0] = 1;
    for (int msk = 0; msk < (1 << n); msk++) {
        popc[msk] = popc[msk >> 1] + (msk & 1);
        for (int i = msk; i; i = (i - 1) & msk) {
            if (!good[i]) continue;
            if (popc[i] & 1) dp[msk] += dp[msk ^ i];
            else dp[msk] -= dp[msk ^ i];
            dp[msk] %= mod;
        }
    } cout << (((dp[(1 << n) - 1] * m) % mod * inv(2)) % mod + mod) % mod;
}
int32_t main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

Compilation message

amusementpark.cpp: In function 'void open_file(std::string)':
amusementpark.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
amusementpark.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2556 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2556 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 2 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2488 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2520 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2556 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 2 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2488 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2520 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2432 KB Output is correct
33 Correct 2 ms 2384 KB Output is correct
34 Correct 1 ms 2640 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 1 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 2384 KB Output is correct
39 Correct 1 ms 2384 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
41 Correct 1 ms 2384 KB Output is correct
42 Correct 2 ms 2384 KB Output is correct
43 Correct 1 ms 2556 KB Output is correct
44 Correct 1 ms 2384 KB Output is correct
45 Correct 1 ms 2384 KB Output is correct
46 Correct 1 ms 2640 KB Output is correct
47 Correct 1 ms 2384 KB Output is correct
48 Correct 1 ms 2520 KB Output is correct
49 Correct 1 ms 2384 KB Output is correct
50 Correct 2 ms 2508 KB Output is correct
51 Correct 1 ms 2384 KB Output is correct
52 Correct 1 ms 2384 KB Output is correct
53 Correct 1 ms 2384 KB Output is correct
54 Correct 1 ms 2384 KB Output is correct
55 Correct 1 ms 2384 KB Output is correct
56 Correct 1 ms 2640 KB Output is correct
57 Correct 1 ms 2384 KB Output is correct
58 Correct 1 ms 2384 KB Output is correct
59 Correct 1 ms 2384 KB Output is correct
60 Correct 1 ms 2384 KB Output is correct
61 Correct 1 ms 2384 KB Output is correct
62 Correct 1 ms 2384 KB Output is correct
63 Correct 2 ms 2384 KB Output is correct
64 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2556 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 2 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2488 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2520 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2432 KB Output is correct
33 Correct 2 ms 2384 KB Output is correct
34 Correct 1 ms 2640 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 1 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 2384 KB Output is correct
39 Correct 1 ms 2384 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
41 Correct 1 ms 2384 KB Output is correct
42 Correct 2 ms 2384 KB Output is correct
43 Correct 1 ms 2556 KB Output is correct
44 Correct 1 ms 2384 KB Output is correct
45 Correct 1 ms 2384 KB Output is correct
46 Correct 1 ms 2640 KB Output is correct
47 Correct 1 ms 2384 KB Output is correct
48 Correct 1 ms 2520 KB Output is correct
49 Correct 1 ms 2384 KB Output is correct
50 Correct 2 ms 2508 KB Output is correct
51 Correct 1 ms 2384 KB Output is correct
52 Correct 1 ms 2384 KB Output is correct
53 Correct 1 ms 2384 KB Output is correct
54 Correct 1 ms 2384 KB Output is correct
55 Correct 1 ms 2384 KB Output is correct
56 Correct 1 ms 2640 KB Output is correct
57 Correct 1 ms 2384 KB Output is correct
58 Correct 1 ms 2384 KB Output is correct
59 Correct 1 ms 2384 KB Output is correct
60 Correct 1 ms 2384 KB Output is correct
61 Correct 1 ms 2384 KB Output is correct
62 Correct 1 ms 2384 KB Output is correct
63 Correct 2 ms 2384 KB Output is correct
64 Correct 1 ms 2384 KB Output is correct
65 Correct 11 ms 2532 KB Output is correct
66 Correct 10 ms 2384 KB Output is correct
67 Correct 13 ms 2384 KB Output is correct
68 Correct 14 ms 2396 KB Output is correct
69 Correct 17 ms 2536 KB Output is correct
70 Correct 14 ms 2384 KB Output is correct
71 Correct 14 ms 2540 KB Output is correct
72 Correct 14 ms 2384 KB Output is correct
73 Correct 13 ms 2536 KB Output is correct
74 Correct 11 ms 2384 KB Output is correct
75 Correct 12 ms 2384 KB Output is correct
76 Correct 12 ms 2384 KB Output is correct
77 Correct 31 ms 2384 KB Output is correct
78 Correct 32 ms 2640 KB Output is correct
79 Correct 27 ms 2384 KB Output is correct
80 Correct 26 ms 2384 KB Output is correct
81 Correct 30 ms 2640 KB Output is correct
82 Correct 27 ms 2552 KB Output is correct
83 Correct 25 ms 2552 KB Output is correct
84 Correct 27 ms 2512 KB Output is correct
85 Correct 48 ms 2640 KB Output is correct
86 Correct 35 ms 2384 KB Output is correct
87 Correct 38 ms 2384 KB Output is correct
88 Correct 42 ms 2384 KB Output is correct
89 Correct 28 ms 2384 KB Output is correct
90 Correct 31 ms 2536 KB Output is correct
91 Correct 31 ms 2384 KB Output is correct
92 Correct 33 ms 2400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2556 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 2 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2488 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2520 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2432 KB Output is correct
33 Correct 2 ms 2384 KB Output is correct
34 Correct 1 ms 2640 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 1 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 2384 KB Output is correct
39 Correct 1 ms 2384 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
41 Correct 1 ms 2384 KB Output is correct
42 Correct 2 ms 2384 KB Output is correct
43 Correct 1 ms 2556 KB Output is correct
44 Correct 1 ms 2384 KB Output is correct
45 Correct 1 ms 2384 KB Output is correct
46 Correct 1 ms 2640 KB Output is correct
47 Correct 1 ms 2384 KB Output is correct
48 Correct 1 ms 2520 KB Output is correct
49 Correct 1 ms 2384 KB Output is correct
50 Correct 2 ms 2508 KB Output is correct
51 Correct 1 ms 2384 KB Output is correct
52 Correct 1 ms 2384 KB Output is correct
53 Correct 1 ms 2384 KB Output is correct
54 Correct 1 ms 2384 KB Output is correct
55 Correct 1 ms 2384 KB Output is correct
56 Correct 1 ms 2640 KB Output is correct
57 Correct 1 ms 2384 KB Output is correct
58 Correct 1 ms 2384 KB Output is correct
59 Correct 1 ms 2384 KB Output is correct
60 Correct 1 ms 2384 KB Output is correct
61 Correct 1 ms 2384 KB Output is correct
62 Correct 1 ms 2384 KB Output is correct
63 Correct 2 ms 2384 KB Output is correct
64 Correct 1 ms 2384 KB Output is correct
65 Correct 11 ms 2532 KB Output is correct
66 Correct 10 ms 2384 KB Output is correct
67 Correct 13 ms 2384 KB Output is correct
68 Correct 14 ms 2396 KB Output is correct
69 Correct 17 ms 2536 KB Output is correct
70 Correct 14 ms 2384 KB Output is correct
71 Correct 14 ms 2540 KB Output is correct
72 Correct 14 ms 2384 KB Output is correct
73 Correct 13 ms 2536 KB Output is correct
74 Correct 11 ms 2384 KB Output is correct
75 Correct 12 ms 2384 KB Output is correct
76 Correct 12 ms 2384 KB Output is correct
77 Correct 31 ms 2384 KB Output is correct
78 Correct 32 ms 2640 KB Output is correct
79 Correct 27 ms 2384 KB Output is correct
80 Correct 26 ms 2384 KB Output is correct
81 Correct 30 ms 2640 KB Output is correct
82 Correct 27 ms 2552 KB Output is correct
83 Correct 25 ms 2552 KB Output is correct
84 Correct 27 ms 2512 KB Output is correct
85 Correct 48 ms 2640 KB Output is correct
86 Correct 35 ms 2384 KB Output is correct
87 Correct 38 ms 2384 KB Output is correct
88 Correct 42 ms 2384 KB Output is correct
89 Correct 28 ms 2384 KB Output is correct
90 Correct 31 ms 2536 KB Output is correct
91 Correct 31 ms 2384 KB Output is correct
92 Correct 33 ms 2400 KB Output is correct
93 Correct 865 ms 3656 KB Output is correct
94 Correct 879 ms 3732 KB Output is correct
95 Correct 901 ms 3700 KB Output is correct
96 Correct 700 ms 3708 KB Output is correct
97 Correct 696 ms 3656 KB Output is correct
98 Correct 680 ms 3708 KB Output is correct
99 Correct 79 ms 2384 KB Output is correct
100 Correct 92 ms 2384 KB Output is correct
101 Correct 77 ms 2552 KB Output is correct
102 Correct 67 ms 2384 KB Output is correct
103 Correct 537 ms 1996 KB Output is correct
104 Correct 320 ms 2644 KB Output is correct
105 Correct 242 ms 2808 KB Output is correct
106 Correct 205 ms 2640 KB Output is correct
107 Correct 1609 ms 3716 KB Output is correct
108 Correct 692 ms 3700 KB Output is correct
109 Correct 599 ms 3656 KB Output is correct
110 Correct 564 ms 3708 KB Output is correct
111 Correct 66 ms 2384 KB Output is correct
112 Correct 64 ms 2384 KB Output is correct
113 Correct 76 ms 2384 KB Output is correct
114 Correct 128 ms 2384 KB Output is correct
115 Correct 95 ms 2384 KB Output is correct
116 Correct 102 ms 2384 KB Output is correct
117 Correct 112 ms 2556 KB Output is correct
118 Correct 89 ms 2384 KB Output is correct
119 Correct 81 ms 2552 KB Output is correct
120 Correct 86 ms 2384 KB Output is correct
121 Correct 94 ms 2384 KB Output is correct
122 Correct 197 ms 2808 KB Output is correct
123 Correct 224 ms 2644 KB Output is correct
124 Correct 180 ms 2640 KB Output is correct
125 Correct 191 ms 2640 KB Output is correct
126 Correct 171 ms 2640 KB Output is correct
127 Correct 179 ms 2640 KB Output is correct
128 Correct 170 ms 2640 KB Output is correct
129 Correct 160 ms 2640 KB Output is correct
130 Correct 170 ms 2640 KB Output is correct
131 Correct 374 ms 2640 KB Output is correct
132 Correct 286 ms 2888 KB Output is correct
133 Correct 309 ms 2640 KB Output is correct
134 Correct 322 ms 2640 KB Output is correct
135 Correct 221 ms 2640 KB Output is correct
136 Correct 232 ms 2640 KB Output is correct
137 Correct 254 ms 2640 KB Output is correct
138 Correct 268 ms 2640 KB Output is correct
139 Correct 197 ms 2640 KB Output is correct
140 Correct 211 ms 2640 KB Output is correct
141 Correct 228 ms 2808 KB Output is correct
142 Correct 525 ms 3632 KB Output is correct
143 Correct 498 ms 3704 KB Output is correct
144 Correct 479 ms 3656 KB Output is correct
145 Correct 493 ms 3648 KB Output is correct
146 Correct 463 ms 3656 KB Output is correct
147 Correct 472 ms 3784 KB Output is correct
148 Correct 545 ms 3712 KB Output is correct
149 Correct 521 ms 3656 KB Output is correct
150 Correct 541 ms 3656 KB Output is correct
151 Correct 576 ms 3656 KB Output is correct
152 Correct 567 ms 3708 KB Output is correct
153 Correct 668 ms 3708 KB Output is correct
154 Correct 667 ms 3624 KB Output is correct
155 Correct 734 ms 3656 KB Output is correct
156 Correct 791 ms 3660 KB Output is correct
157 Correct 681 ms 3656 KB Output is correct
158 Correct 758 ms 3704 KB Output is correct
159 Correct 611 ms 3656 KB Output is correct
160 Correct 607 ms 3656 KB Output is correct
161 Correct 672 ms 3656 KB Output is correct
162 Correct 551 ms 3716 KB Output is correct
163 Correct 585 ms 3772 KB Output is correct
164 Correct 543 ms 3712 KB Output is correct
165 Correct 554 ms 3576 KB Output is correct
166 Correct 574 ms 3780 KB Output is correct
167 Correct 602 ms 3720 KB Output is correct