Submission #885518

# Submission time Handle Problem Language Result Execution time Memory
885518 2023-12-09T22:44:29 Z beaboss Amusement Park (CEOI19_amusementpark) C++14
100 / 100
2173 ms 6828 KB
// Source: https://oj.uz/problem/view/CEOI19_amusementpark
// 

#include "bits/stdc++.h"

using namespace std;

#define s second
#define f first
#define pb push_back

typedef long long ll;

typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

typedef vector<ll> vi;

#define FOR(i, a, b) for (ll i = (a); i<b; i++)

const ll N = 18;

ll indep[1 << N];
ll dp[1 << N];
ll sz[1 << N];
vi adj[N];
const ll MOD = 998244353;

ll binpow(ll x, ll n) {
	assert(n >= 0);
	x %= MOD;  // note: m * m must be less than 2^63 to avoid ll overflow
	ll res = 1;
	while (n > 0) {
		if (n % 2 == 1) { res = res * x % MOD; }
		x = x * x % MOD;
		n /= 2;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll n, m;
	cin >> n >> m;


	FOR(i, 0, m) {
		ll a, b;
		cin >> a >> b;
		a--;b--;
		adj[a].pb(b);
		adj[b].pb(a);

	}

	FOR(i, 0, 1 << n) {
		dp[i]=0;
		indep[i]=true;
		sz[i] = 0;
		FOR(j, 0, n) {
			if ((1 << j) & i) {
				for (auto val: adj[j]) {
					if ((1 << val) & i) indep[i]=false;
				}

				sz[i] ++;
			}
		}

		// cout << i << ' ' << indep[i] << endl;

		if (sz[i] % 2 == 1) sz[i] = 1;
		else sz[i] = -1;
	}

	dp[0] = 1;


	FOR(i, 1, 1 << n) {
		dp[i] = 0;
		for (ll j = i; j; j = (j - 1) & i) {
			// cout << ' ' << j << dp[i ^ j] << dp[i] << sz[j] << indep[j] << endl;
			if (indep[j]) dp[i] = ((dp[i] + dp[i ^ j] * sz[j])) % MOD;

		}

		// cout << i << ' ' << dp[i] << endl;	
	}
	dp[(1 << n) - 1] = (dp[(1 << n) - 1] + MOD) % MOD;
	cout << ((dp[(1 << n) - 1] * m) % MOD * binpow(2, MOD - 2)) % MOD << endl;


}












# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 3 ms 4556 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4448 KB Output is correct
32 Correct 1 ms 4448 KB Output is correct
33 Correct 1 ms 4448 KB Output is correct
34 Correct 1 ms 4448 KB Output is correct
35 Correct 1 ms 4448 KB Output is correct
36 Correct 1 ms 4448 KB Output is correct
37 Correct 1 ms 4448 KB Output is correct
38 Correct 1 ms 4448 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4448 KB Output is correct
43 Correct 1 ms 4448 KB Output is correct
44 Correct 1 ms 4448 KB Output is correct
45 Correct 1 ms 4448 KB Output is correct
46 Correct 1 ms 4452 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4452 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4560 KB Output is correct
52 Correct 1 ms 4440 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4448 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 1 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 3 ms 4556 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4448 KB Output is correct
32 Correct 1 ms 4448 KB Output is correct
33 Correct 1 ms 4448 KB Output is correct
34 Correct 1 ms 4448 KB Output is correct
35 Correct 1 ms 4448 KB Output is correct
36 Correct 1 ms 4448 KB Output is correct
37 Correct 1 ms 4448 KB Output is correct
38 Correct 1 ms 4448 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4448 KB Output is correct
43 Correct 1 ms 4448 KB Output is correct
44 Correct 1 ms 4448 KB Output is correct
45 Correct 1 ms 4448 KB Output is correct
46 Correct 1 ms 4452 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4452 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4560 KB Output is correct
52 Correct 1 ms 4440 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4448 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 1 ms 4564 KB Output is correct
65 Correct 10 ms 4444 KB Output is correct
66 Correct 12 ms 4700 KB Output is correct
67 Correct 10 ms 4700 KB Output is correct
68 Correct 10 ms 4608 KB Output is correct
69 Correct 14 ms 4700 KB Output is correct
70 Correct 14 ms 4444 KB Output is correct
71 Correct 15 ms 4444 KB Output is correct
72 Correct 12 ms 4444 KB Output is correct
73 Correct 10 ms 4444 KB Output is correct
74 Correct 10 ms 4560 KB Output is correct
75 Correct 11 ms 4444 KB Output is correct
76 Correct 11 ms 4692 KB Output is correct
77 Correct 26 ms 4700 KB Output is correct
78 Correct 25 ms 4696 KB Output is correct
79 Correct 26 ms 4700 KB Output is correct
80 Correct 25 ms 4696 KB Output is correct
81 Correct 27 ms 4696 KB Output is correct
82 Correct 25 ms 4696 KB Output is correct
83 Correct 28 ms 4700 KB Output is correct
84 Correct 26 ms 4732 KB Output is correct
85 Correct 55 ms 4696 KB Output is correct
86 Correct 40 ms 4808 KB Output is correct
87 Correct 42 ms 4700 KB Output is correct
88 Correct 42 ms 4696 KB Output is correct
89 Correct 26 ms 4808 KB Output is correct
90 Correct 32 ms 4660 KB Output is correct
91 Correct 30 ms 4696 KB Output is correct
92 Correct 37 ms 4816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 3 ms 4556 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4448 KB Output is correct
32 Correct 1 ms 4448 KB Output is correct
33 Correct 1 ms 4448 KB Output is correct
34 Correct 1 ms 4448 KB Output is correct
35 Correct 1 ms 4448 KB Output is correct
36 Correct 1 ms 4448 KB Output is correct
37 Correct 1 ms 4448 KB Output is correct
38 Correct 1 ms 4448 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4448 KB Output is correct
43 Correct 1 ms 4448 KB Output is correct
44 Correct 1 ms 4448 KB Output is correct
45 Correct 1 ms 4448 KB Output is correct
46 Correct 1 ms 4452 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4452 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4560 KB Output is correct
52 Correct 1 ms 4440 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4448 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 1 ms 4564 KB Output is correct
65 Correct 10 ms 4444 KB Output is correct
66 Correct 12 ms 4700 KB Output is correct
67 Correct 10 ms 4700 KB Output is correct
68 Correct 10 ms 4608 KB Output is correct
69 Correct 14 ms 4700 KB Output is correct
70 Correct 14 ms 4444 KB Output is correct
71 Correct 15 ms 4444 KB Output is correct
72 Correct 12 ms 4444 KB Output is correct
73 Correct 10 ms 4444 KB Output is correct
74 Correct 10 ms 4560 KB Output is correct
75 Correct 11 ms 4444 KB Output is correct
76 Correct 11 ms 4692 KB Output is correct
77 Correct 26 ms 4700 KB Output is correct
78 Correct 25 ms 4696 KB Output is correct
79 Correct 26 ms 4700 KB Output is correct
80 Correct 25 ms 4696 KB Output is correct
81 Correct 27 ms 4696 KB Output is correct
82 Correct 25 ms 4696 KB Output is correct
83 Correct 28 ms 4700 KB Output is correct
84 Correct 26 ms 4732 KB Output is correct
85 Correct 55 ms 4696 KB Output is correct
86 Correct 40 ms 4808 KB Output is correct
87 Correct 42 ms 4700 KB Output is correct
88 Correct 42 ms 4696 KB Output is correct
89 Correct 26 ms 4808 KB Output is correct
90 Correct 32 ms 4660 KB Output is correct
91 Correct 30 ms 4696 KB Output is correct
92 Correct 37 ms 4816 KB Output is correct
93 Correct 949 ms 6584 KB Output is correct
94 Correct 989 ms 6736 KB Output is correct
95 Correct 933 ms 6588 KB Output is correct
96 Correct 673 ms 6768 KB Output is correct
97 Correct 671 ms 6600 KB Output is correct
98 Correct 767 ms 6736 KB Output is correct
99 Correct 72 ms 5056 KB Output is correct
100 Correct 78 ms 4960 KB Output is correct
101 Correct 74 ms 5192 KB Output is correct
102 Correct 67 ms 4952 KB Output is correct
103 Correct 688 ms 5564 KB Output is correct
104 Correct 311 ms 5468 KB Output is correct
105 Correct 265 ms 5564 KB Output is correct
106 Correct 199 ms 5468 KB Output is correct
107 Correct 2173 ms 6584 KB Output is correct
108 Correct 775 ms 6596 KB Output is correct
109 Correct 548 ms 6584 KB Output is correct
110 Correct 512 ms 6592 KB Output is correct
111 Correct 73 ms 4952 KB Output is correct
112 Correct 64 ms 5056 KB Output is correct
113 Correct 63 ms 4944 KB Output is correct
114 Correct 165 ms 5052 KB Output is correct
115 Correct 104 ms 5212 KB Output is correct
116 Correct 120 ms 4936 KB Output is correct
117 Correct 127 ms 5056 KB Output is correct
118 Correct 73 ms 5060 KB Output is correct
119 Correct 93 ms 5060 KB Output is correct
120 Correct 98 ms 5056 KB Output is correct
121 Correct 100 ms 4956 KB Output is correct
122 Correct 187 ms 5568 KB Output is correct
123 Correct 173 ms 5520 KB Output is correct
124 Correct 187 ms 5572 KB Output is correct
125 Correct 171 ms 5572 KB Output is correct
126 Correct 168 ms 5580 KB Output is correct
127 Correct 177 ms 5568 KB Output is correct
128 Correct 171 ms 5460 KB Output is correct
129 Correct 176 ms 5764 KB Output is correct
130 Correct 171 ms 5456 KB Output is correct
131 Correct 422 ms 5568 KB Output is correct
132 Correct 248 ms 5464 KB Output is correct
133 Correct 367 ms 5568 KB Output is correct
134 Correct 356 ms 5568 KB Output is correct
135 Correct 251 ms 5468 KB Output is correct
136 Correct 232 ms 5568 KB Output is correct
137 Correct 290 ms 5564 KB Output is correct
138 Correct 305 ms 5468 KB Output is correct
139 Correct 211 ms 5568 KB Output is correct
140 Correct 248 ms 5480 KB Output is correct
141 Correct 202 ms 5712 KB Output is correct
142 Correct 503 ms 6452 KB Output is correct
143 Correct 464 ms 6736 KB Output is correct
144 Correct 474 ms 6592 KB Output is correct
145 Correct 457 ms 6480 KB Output is correct
146 Correct 487 ms 6588 KB Output is correct
147 Correct 474 ms 6356 KB Output is correct
148 Correct 504 ms 6480 KB Output is correct
149 Correct 480 ms 6596 KB Output is correct
150 Correct 498 ms 6512 KB Output is correct
151 Correct 569 ms 6560 KB Output is correct
152 Correct 547 ms 6736 KB Output is correct
153 Correct 701 ms 6592 KB Output is correct
154 Correct 734 ms 6592 KB Output is correct
155 Correct 730 ms 6484 KB Output is correct
156 Correct 816 ms 6728 KB Output is correct
157 Correct 792 ms 6828 KB Output is correct
158 Correct 857 ms 6464 KB Output is correct
159 Correct 595 ms 6588 KB Output is correct
160 Correct 673 ms 6588 KB Output is correct
161 Correct 734 ms 6592 KB Output is correct
162 Correct 601 ms 6588 KB Output is correct
163 Correct 580 ms 6408 KB Output is correct
164 Correct 556 ms 6484 KB Output is correct
165 Correct 551 ms 6736 KB Output is correct
166 Correct 593 ms 6588 KB Output is correct
167 Correct 614 ms 6740 KB Output is correct