Submission #468312

# Submission time Handle Problem Language Result Execution time Memory
468312 2021-08-27T15:03:32 Z warner1129 Amusement Park (CEOI19_amusementpark) C++17
100 / 100
359 ms 39364 KB
#include <bits/stdc++.h>

#define ff first
#define ss second

using namespace std;

template <uint32_t mod> struct modint {
	uint32_t val;
public:
	static modint raw(int v) { modint x; x.val = v; return x; }
	modint() : val(0) {}
	template <class T>
	modint(T v) { int64_t x = (int64_t)(v%(int64_t)(mod)); if (x < 0) x += mod; val = (uint32_t)(x); }
	modint(bool v) { val = ((unsigned int)(v) % mod); }
	modint& operator++() { val++; if (val == mod) val = 0; return *this; }
	modint& operator--() { if (val == 0) val = mod; val--; return *this; }
	modint operator++(int) { modint result = *this; ++*this; return result; }
	modint operator--(int) { modint result = *this; --*this; return result; }
	modint& operator+=(const modint& rhs) { val += rhs.val; if (val >= mod) val -= mod; return *this; }
	modint& operator-=(const modint& rhs) { val -= rhs.val; if (val >= mod) val += mod; return *this; }
	modint& operator*=(const modint& rhs) { uint64_t z = val; z *= rhs.val; val = (uint32_t)(z % mod); return *this; }
	modint& operator/=(const modint& rhs) { return *this = *this * rhs.inv(); }
	modint operator+() const { return *this; }
	modint operator-() const { return modint() - *this; }
	modint pow(long long n) const { modint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
	modint inv() const { return pow(mod-2); }
	friend modint operator+(const modint& lhs, const modint& rhs) { return modint(lhs) += rhs; }
	friend modint operator-(const modint& lhs, const modint& rhs) { return modint(lhs) -= rhs; }
	friend modint operator*(const modint& lhs, const modint& rhs) { return modint(lhs) *= rhs; }
	friend modint operator/(const modint& lhs, const modint& rhs) { return modint(lhs) /= rhs; }
	friend bool operator==(const modint& lhs, const modint& rhs) { return lhs.val == rhs.val; }
	friend bool operator!=(const modint& lhs, const modint& rhs) { return lhs.val != rhs.val; }
};

using mint = modint<998244353>;

const int maxn = 18;

mint g[1<<maxn][maxn+1], ig[1<<maxn][maxn+1];
int edge[maxn * maxn];
int n, m, lim;

bool check(const int &s) {
	for (int i = 1; i <= m; i++)
		if ((s & edge[i]) == edge[i])
			return false;
	return true;
}

void FWT() {
	for (int i = 1; i < lim; i<<=1)
		for (int j = 0; j < lim; j += (i<<1))
			for (int k = 0; k < i; k++)
				for (int p = 0; p <= n; p++)
					g[i | j | k][p] += g[j | k][p];
}

void INV() {
	for (int s = 1; s < lim; s++) {
		mint inv = ig[s][0] = g[s][0].inv();
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < i; j++)
				ig[s][i] -= ig[s][j] * g[s][i-j];
			ig[s][i] *= inv;
		}
	}
}

void IFWT() {
	for (int i = 1; i < lim; i<<=1)
		for (int j = 0; j < lim; j += (i<<1))
			for (int k = 0; k < i; k++)
				for (int p = 0; p <= n; p++)
					ig[i | j | k][p] -= ig[j | k][p];
}

void solve() {
	cin >> n >> m;
	lim = (1<<n);
	for (int i = 1, x, y; i <= m; i++)
		cin >> x >> y, --x, --y, edge[i] = ((1<<x) | (1<<y));
	g[0][0] = 1;
	for (int s = 1, cnt; s < lim; s++)
		if (check(s)) g[s][cnt] = (((cnt = __builtin_popcount(s)) & 1) ? mint(-1) : mint(1));
	FWT();
	INV();
	IFWT();	
	cout << (ig[lim-1][n] * mint(m) * mint(499122177)).val << '\n';
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}

Compilation message

amusementpark.cpp: In function 'void solve()':
amusementpark.cpp:85:36: warning: operation on 'cnt' may be undefined [-Wsequence-point]
   85 |   if (check(s)) g[s][cnt] = (((cnt = __builtin_popcount(s)) & 1) ? mint(-1) : mint(1));
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 39180 KB Output is correct
2 Correct 17 ms 39248 KB Output is correct
3 Correct 17 ms 39244 KB Output is correct
4 Correct 16 ms 39244 KB Output is correct
5 Correct 18 ms 39184 KB Output is correct
6 Correct 17 ms 39304 KB Output is correct
7 Correct 18 ms 39244 KB Output is correct
8 Correct 18 ms 39232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 39180 KB Output is correct
2 Correct 17 ms 39248 KB Output is correct
3 Correct 17 ms 39244 KB Output is correct
4 Correct 16 ms 39244 KB Output is correct
5 Correct 18 ms 39184 KB Output is correct
6 Correct 17 ms 39304 KB Output is correct
7 Correct 18 ms 39244 KB Output is correct
8 Correct 18 ms 39232 KB Output is correct
9 Correct 18 ms 39312 KB Output is correct
10 Correct 17 ms 39244 KB Output is correct
11 Correct 18 ms 39304 KB Output is correct
12 Correct 18 ms 39228 KB Output is correct
13 Correct 19 ms 39300 KB Output is correct
14 Correct 19 ms 39248 KB Output is correct
15 Correct 18 ms 39204 KB Output is correct
16 Correct 18 ms 39296 KB Output is correct
17 Correct 18 ms 39244 KB Output is correct
18 Correct 18 ms 39224 KB Output is correct
19 Correct 18 ms 39264 KB Output is correct
20 Correct 19 ms 39224 KB Output is correct
21 Correct 18 ms 39244 KB Output is correct
22 Correct 18 ms 39188 KB Output is correct
23 Correct 19 ms 39300 KB Output is correct
24 Correct 17 ms 39272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 39180 KB Output is correct
2 Correct 17 ms 39248 KB Output is correct
3 Correct 17 ms 39244 KB Output is correct
4 Correct 16 ms 39244 KB Output is correct
5 Correct 18 ms 39184 KB Output is correct
6 Correct 17 ms 39304 KB Output is correct
7 Correct 18 ms 39244 KB Output is correct
8 Correct 18 ms 39232 KB Output is correct
9 Correct 18 ms 39312 KB Output is correct
10 Correct 17 ms 39244 KB Output is correct
11 Correct 18 ms 39304 KB Output is correct
12 Correct 18 ms 39228 KB Output is correct
13 Correct 19 ms 39300 KB Output is correct
14 Correct 19 ms 39248 KB Output is correct
15 Correct 18 ms 39204 KB Output is correct
16 Correct 18 ms 39296 KB Output is correct
17 Correct 18 ms 39244 KB Output is correct
18 Correct 18 ms 39224 KB Output is correct
19 Correct 18 ms 39264 KB Output is correct
20 Correct 19 ms 39224 KB Output is correct
21 Correct 18 ms 39244 KB Output is correct
22 Correct 18 ms 39188 KB Output is correct
23 Correct 19 ms 39300 KB Output is correct
24 Correct 17 ms 39272 KB Output is correct
25 Correct 17 ms 39244 KB Output is correct
26 Correct 18 ms 39296 KB Output is correct
27 Correct 19 ms 39244 KB Output is correct
28 Correct 18 ms 39200 KB Output is correct
29 Correct 18 ms 39244 KB Output is correct
30 Correct 18 ms 39236 KB Output is correct
31 Correct 18 ms 39244 KB Output is correct
32 Correct 18 ms 39304 KB Output is correct
33 Correct 19 ms 39288 KB Output is correct
34 Correct 19 ms 39244 KB Output is correct
35 Correct 18 ms 39224 KB Output is correct
36 Correct 19 ms 39244 KB Output is correct
37 Correct 18 ms 39304 KB Output is correct
38 Correct 18 ms 39244 KB Output is correct
39 Correct 19 ms 39248 KB Output is correct
40 Correct 19 ms 39260 KB Output is correct
41 Correct 19 ms 39232 KB Output is correct
42 Correct 19 ms 39272 KB Output is correct
43 Correct 18 ms 39308 KB Output is correct
44 Correct 18 ms 39244 KB Output is correct
45 Correct 18 ms 39304 KB Output is correct
46 Correct 18 ms 39284 KB Output is correct
47 Correct 19 ms 39244 KB Output is correct
48 Correct 18 ms 39304 KB Output is correct
49 Correct 19 ms 39236 KB Output is correct
50 Correct 19 ms 39216 KB Output is correct
51 Correct 18 ms 39244 KB Output is correct
52 Correct 18 ms 39260 KB Output is correct
53 Correct 18 ms 39300 KB Output is correct
54 Correct 18 ms 39232 KB Output is correct
55 Correct 18 ms 39244 KB Output is correct
56 Correct 18 ms 39272 KB Output is correct
57 Correct 19 ms 39300 KB Output is correct
58 Correct 19 ms 39244 KB Output is correct
59 Correct 18 ms 39236 KB Output is correct
60 Correct 19 ms 39276 KB Output is correct
61 Correct 18 ms 39244 KB Output is correct
62 Correct 18 ms 39192 KB Output is correct
63 Correct 18 ms 39244 KB Output is correct
64 Correct 19 ms 39208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 39180 KB Output is correct
2 Correct 17 ms 39248 KB Output is correct
3 Correct 17 ms 39244 KB Output is correct
4 Correct 16 ms 39244 KB Output is correct
5 Correct 18 ms 39184 KB Output is correct
6 Correct 17 ms 39304 KB Output is correct
7 Correct 18 ms 39244 KB Output is correct
8 Correct 18 ms 39232 KB Output is correct
9 Correct 18 ms 39312 KB Output is correct
10 Correct 17 ms 39244 KB Output is correct
11 Correct 18 ms 39304 KB Output is correct
12 Correct 18 ms 39228 KB Output is correct
13 Correct 19 ms 39300 KB Output is correct
14 Correct 19 ms 39248 KB Output is correct
15 Correct 18 ms 39204 KB Output is correct
16 Correct 18 ms 39296 KB Output is correct
17 Correct 18 ms 39244 KB Output is correct
18 Correct 18 ms 39224 KB Output is correct
19 Correct 18 ms 39264 KB Output is correct
20 Correct 19 ms 39224 KB Output is correct
21 Correct 18 ms 39244 KB Output is correct
22 Correct 18 ms 39188 KB Output is correct
23 Correct 19 ms 39300 KB Output is correct
24 Correct 17 ms 39272 KB Output is correct
25 Correct 17 ms 39244 KB Output is correct
26 Correct 18 ms 39296 KB Output is correct
27 Correct 19 ms 39244 KB Output is correct
28 Correct 18 ms 39200 KB Output is correct
29 Correct 18 ms 39244 KB Output is correct
30 Correct 18 ms 39236 KB Output is correct
31 Correct 18 ms 39244 KB Output is correct
32 Correct 18 ms 39304 KB Output is correct
33 Correct 19 ms 39288 KB Output is correct
34 Correct 19 ms 39244 KB Output is correct
35 Correct 18 ms 39224 KB Output is correct
36 Correct 19 ms 39244 KB Output is correct
37 Correct 18 ms 39304 KB Output is correct
38 Correct 18 ms 39244 KB Output is correct
39 Correct 19 ms 39248 KB Output is correct
40 Correct 19 ms 39260 KB Output is correct
41 Correct 19 ms 39232 KB Output is correct
42 Correct 19 ms 39272 KB Output is correct
43 Correct 18 ms 39308 KB Output is correct
44 Correct 18 ms 39244 KB Output is correct
45 Correct 18 ms 39304 KB Output is correct
46 Correct 18 ms 39284 KB Output is correct
47 Correct 19 ms 39244 KB Output is correct
48 Correct 18 ms 39304 KB Output is correct
49 Correct 19 ms 39236 KB Output is correct
50 Correct 19 ms 39216 KB Output is correct
51 Correct 18 ms 39244 KB Output is correct
52 Correct 18 ms 39260 KB Output is correct
53 Correct 18 ms 39300 KB Output is correct
54 Correct 18 ms 39232 KB Output is correct
55 Correct 18 ms 39244 KB Output is correct
56 Correct 18 ms 39272 KB Output is correct
57 Correct 19 ms 39300 KB Output is correct
58 Correct 19 ms 39244 KB Output is correct
59 Correct 18 ms 39236 KB Output is correct
60 Correct 19 ms 39276 KB Output is correct
61 Correct 18 ms 39244 KB Output is correct
62 Correct 18 ms 39192 KB Output is correct
63 Correct 18 ms 39244 KB Output is correct
64 Correct 19 ms 39208 KB Output is correct
65 Correct 30 ms 39244 KB Output is correct
66 Correct 30 ms 39244 KB Output is correct
67 Correct 30 ms 39276 KB Output is correct
68 Correct 30 ms 39304 KB Output is correct
69 Correct 30 ms 39308 KB Output is correct
70 Correct 30 ms 39284 KB Output is correct
71 Correct 30 ms 39244 KB Output is correct
72 Correct 31 ms 39236 KB Output is correct
73 Correct 30 ms 39244 KB Output is correct
74 Correct 31 ms 39188 KB Output is correct
75 Correct 30 ms 39228 KB Output is correct
76 Correct 30 ms 39244 KB Output is correct
77 Correct 46 ms 39244 KB Output is correct
78 Correct 47 ms 39272 KB Output is correct
79 Correct 45 ms 39244 KB Output is correct
80 Correct 47 ms 39244 KB Output is correct
81 Correct 46 ms 39244 KB Output is correct
82 Correct 47 ms 39280 KB Output is correct
83 Correct 46 ms 39184 KB Output is correct
84 Correct 47 ms 39220 KB Output is correct
85 Correct 47 ms 39244 KB Output is correct
86 Correct 46 ms 39284 KB Output is correct
87 Correct 47 ms 39244 KB Output is correct
88 Correct 46 ms 39208 KB Output is correct
89 Correct 48 ms 39284 KB Output is correct
90 Correct 45 ms 39244 KB Output is correct
91 Correct 45 ms 39244 KB Output is correct
92 Correct 46 ms 39280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 39180 KB Output is correct
2 Correct 17 ms 39248 KB Output is correct
3 Correct 17 ms 39244 KB Output is correct
4 Correct 16 ms 39244 KB Output is correct
5 Correct 18 ms 39184 KB Output is correct
6 Correct 17 ms 39304 KB Output is correct
7 Correct 18 ms 39244 KB Output is correct
8 Correct 18 ms 39232 KB Output is correct
9 Correct 18 ms 39312 KB Output is correct
10 Correct 17 ms 39244 KB Output is correct
11 Correct 18 ms 39304 KB Output is correct
12 Correct 18 ms 39228 KB Output is correct
13 Correct 19 ms 39300 KB Output is correct
14 Correct 19 ms 39248 KB Output is correct
15 Correct 18 ms 39204 KB Output is correct
16 Correct 18 ms 39296 KB Output is correct
17 Correct 18 ms 39244 KB Output is correct
18 Correct 18 ms 39224 KB Output is correct
19 Correct 18 ms 39264 KB Output is correct
20 Correct 19 ms 39224 KB Output is correct
21 Correct 18 ms 39244 KB Output is correct
22 Correct 18 ms 39188 KB Output is correct
23 Correct 19 ms 39300 KB Output is correct
24 Correct 17 ms 39272 KB Output is correct
25 Correct 17 ms 39244 KB Output is correct
26 Correct 18 ms 39296 KB Output is correct
27 Correct 19 ms 39244 KB Output is correct
28 Correct 18 ms 39200 KB Output is correct
29 Correct 18 ms 39244 KB Output is correct
30 Correct 18 ms 39236 KB Output is correct
31 Correct 18 ms 39244 KB Output is correct
32 Correct 18 ms 39304 KB Output is correct
33 Correct 19 ms 39288 KB Output is correct
34 Correct 19 ms 39244 KB Output is correct
35 Correct 18 ms 39224 KB Output is correct
36 Correct 19 ms 39244 KB Output is correct
37 Correct 18 ms 39304 KB Output is correct
38 Correct 18 ms 39244 KB Output is correct
39 Correct 19 ms 39248 KB Output is correct
40 Correct 19 ms 39260 KB Output is correct
41 Correct 19 ms 39232 KB Output is correct
42 Correct 19 ms 39272 KB Output is correct
43 Correct 18 ms 39308 KB Output is correct
44 Correct 18 ms 39244 KB Output is correct
45 Correct 18 ms 39304 KB Output is correct
46 Correct 18 ms 39284 KB Output is correct
47 Correct 19 ms 39244 KB Output is correct
48 Correct 18 ms 39304 KB Output is correct
49 Correct 19 ms 39236 KB Output is correct
50 Correct 19 ms 39216 KB Output is correct
51 Correct 18 ms 39244 KB Output is correct
52 Correct 18 ms 39260 KB Output is correct
53 Correct 18 ms 39300 KB Output is correct
54 Correct 18 ms 39232 KB Output is correct
55 Correct 18 ms 39244 KB Output is correct
56 Correct 18 ms 39272 KB Output is correct
57 Correct 19 ms 39300 KB Output is correct
58 Correct 19 ms 39244 KB Output is correct
59 Correct 18 ms 39236 KB Output is correct
60 Correct 19 ms 39276 KB Output is correct
61 Correct 18 ms 39244 KB Output is correct
62 Correct 18 ms 39192 KB Output is correct
63 Correct 18 ms 39244 KB Output is correct
64 Correct 19 ms 39208 KB Output is correct
65 Correct 30 ms 39244 KB Output is correct
66 Correct 30 ms 39244 KB Output is correct
67 Correct 30 ms 39276 KB Output is correct
68 Correct 30 ms 39304 KB Output is correct
69 Correct 30 ms 39308 KB Output is correct
70 Correct 30 ms 39284 KB Output is correct
71 Correct 30 ms 39244 KB Output is correct
72 Correct 31 ms 39236 KB Output is correct
73 Correct 30 ms 39244 KB Output is correct
74 Correct 31 ms 39188 KB Output is correct
75 Correct 30 ms 39228 KB Output is correct
76 Correct 30 ms 39244 KB Output is correct
77 Correct 46 ms 39244 KB Output is correct
78 Correct 47 ms 39272 KB Output is correct
79 Correct 45 ms 39244 KB Output is correct
80 Correct 47 ms 39244 KB Output is correct
81 Correct 46 ms 39244 KB Output is correct
82 Correct 47 ms 39280 KB Output is correct
83 Correct 46 ms 39184 KB Output is correct
84 Correct 47 ms 39220 KB Output is correct
85 Correct 47 ms 39244 KB Output is correct
86 Correct 46 ms 39284 KB Output is correct
87 Correct 47 ms 39244 KB Output is correct
88 Correct 46 ms 39208 KB Output is correct
89 Correct 48 ms 39284 KB Output is correct
90 Correct 45 ms 39244 KB Output is correct
91 Correct 45 ms 39244 KB Output is correct
92 Correct 46 ms 39280 KB Output is correct
93 Correct 335 ms 39244 KB Output is correct
94 Correct 326 ms 39244 KB Output is correct
95 Correct 326 ms 39300 KB Output is correct
96 Correct 336 ms 39364 KB Output is correct
97 Correct 343 ms 39300 KB Output is correct
98 Correct 341 ms 39296 KB Output is correct
99 Correct 80 ms 39260 KB Output is correct
100 Correct 83 ms 39244 KB Output is correct
101 Correct 82 ms 39288 KB Output is correct
102 Correct 82 ms 39292 KB Output is correct
103 Correct 150 ms 39284 KB Output is correct
104 Correct 155 ms 39244 KB Output is correct
105 Correct 158 ms 39244 KB Output is correct
106 Correct 163 ms 39244 KB Output is correct
107 Correct 318 ms 39280 KB Output is correct
108 Correct 341 ms 39284 KB Output is correct
109 Correct 353 ms 39284 KB Output is correct
110 Correct 347 ms 39232 KB Output is correct
111 Correct 84 ms 39188 KB Output is correct
112 Correct 84 ms 39244 KB Output is correct
113 Correct 82 ms 39284 KB Output is correct
114 Correct 81 ms 39204 KB Output is correct
115 Correct 79 ms 39244 KB Output is correct
116 Correct 78 ms 39176 KB Output is correct
117 Correct 78 ms 39280 KB Output is correct
118 Correct 79 ms 39244 KB Output is correct
119 Correct 81 ms 39204 KB Output is correct
120 Correct 80 ms 39180 KB Output is correct
121 Correct 78 ms 39284 KB Output is correct
122 Correct 168 ms 39364 KB Output is correct
123 Correct 162 ms 39296 KB Output is correct
124 Correct 165 ms 39184 KB Output is correct
125 Correct 164 ms 39284 KB Output is correct
126 Correct 166 ms 39280 KB Output is correct
127 Correct 164 ms 39244 KB Output is correct
128 Correct 161 ms 39292 KB Output is correct
129 Correct 161 ms 39244 KB Output is correct
130 Correct 158 ms 39288 KB Output is correct
131 Correct 156 ms 39288 KB Output is correct
132 Correct 161 ms 39364 KB Output is correct
133 Correct 159 ms 39236 KB Output is correct
134 Correct 150 ms 39244 KB Output is correct
135 Correct 156 ms 39244 KB Output is correct
136 Correct 162 ms 39352 KB Output is correct
137 Correct 163 ms 39284 KB Output is correct
138 Correct 153 ms 39296 KB Output is correct
139 Correct 159 ms 39284 KB Output is correct
140 Correct 160 ms 39280 KB Output is correct
141 Correct 159 ms 39228 KB Output is correct
142 Correct 352 ms 39296 KB Output is correct
143 Correct 354 ms 39364 KB Output is correct
144 Correct 338 ms 39176 KB Output is correct
145 Correct 337 ms 39284 KB Output is correct
146 Correct 332 ms 39280 KB Output is correct
147 Correct 318 ms 39288 KB Output is correct
148 Correct 359 ms 39284 KB Output is correct
149 Correct 353 ms 39280 KB Output is correct
150 Correct 346 ms 39244 KB Output is correct
151 Correct 341 ms 39280 KB Output is correct
152 Correct 349 ms 39280 KB Output is correct
153 Correct 340 ms 39288 KB Output is correct
154 Correct 339 ms 39364 KB Output is correct
155 Correct 336 ms 39292 KB Output is correct
156 Correct 320 ms 39284 KB Output is correct
157 Correct 338 ms 39288 KB Output is correct
158 Correct 339 ms 39364 KB Output is correct
159 Correct 327 ms 39288 KB Output is correct
160 Correct 336 ms 39244 KB Output is correct
161 Correct 314 ms 39292 KB Output is correct
162 Correct 328 ms 39364 KB Output is correct
163 Correct 329 ms 39188 KB Output is correct
164 Correct 332 ms 39288 KB Output is correct
165 Correct 350 ms 39284 KB Output is correct
166 Correct 331 ms 39280 KB Output is correct
167 Correct 315 ms 39184 KB Output is correct