Submission #752972

# Submission time Handle Problem Language Result Execution time Memory
752972 2023-06-04T11:28:40 Z ono_de206 Amusement Park (CEOI19_amusementpark) C++14
100 / 100
1414 ms 6688 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

#define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
	out << c.first << ' ' << c.second;
    return out;
}

template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
	const int sz = v.size();
	for (int i = 0; i < sz; i++) {
		if (i) out << ' ';
		out << v[i];
	}
    return out;
}

template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
	for (T &x : v) in >> x;
    return in;
}


template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}

const int mxn = 21, mod = 998244353;
int dp[1 << mxn], can[1 << mxn], cnt[1 << mxn], g[mxn];

void add(int &x, int y) {
	x += y;
	if(x >= mod) x -= mod;
}

void sub(int &x, int y) {
	x -= y;
	if(x < 0) x += mod;
}

void go() {
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y; x--; y--;
		g[x] |= (1 << y);
		g[y] |= (1 << x);
	}
	for(int i = 0; i < (1 << n); i++) {
		can[i] = 1;
		cnt[i] = cnt[i / 2] + (i & 1);
		for(int j = 0; j < n; j++) {
			if(((i >> j) & 1) && (i & g[j])) {
				can[i] = 0;
				break;
			}
		}
	}
	dp[0] = 1;
	for(int i = 1; i < (1 << n); i++) {
		for(int j = i; j; j = (j - 1) & i) {
			if(can[j]) {
				if(cnt[j] & 1) add(dp[i], dp[i ^ j]);
				else sub(dp[i], dp[i ^ j]);
			}
		}
	}
	cout << (dp[(1 << n) - 1] * m % mod * (mod + 1) / 2 % mod) << '\n';
}

signed main() {
	// #ifndef ONO
	// freopen("file.in", "r", stdin);
	// freopen("file.out", "w", stdout);
	// #endif
	fast;
	int t = 1;
	// cin >> t;
	while(t--) {
		go();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 328 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 328 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 324 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 324 KB Output is correct
62 Correct 1 ms 324 KB Output is correct
63 Correct 1 ms 328 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 328 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 328 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 324 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 324 KB Output is correct
62 Correct 1 ms 324 KB Output is correct
63 Correct 1 ms 328 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 9 ms 724 KB Output is correct
66 Correct 7 ms 724 KB Output is correct
67 Correct 7 ms 724 KB Output is correct
68 Correct 8 ms 724 KB Output is correct
69 Correct 12 ms 728 KB Output is correct
70 Correct 9 ms 724 KB Output is correct
71 Correct 10 ms 724 KB Output is correct
72 Correct 10 ms 724 KB Output is correct
73 Correct 8 ms 724 KB Output is correct
74 Correct 8 ms 708 KB Output is correct
75 Correct 8 ms 708 KB Output is correct
76 Correct 8 ms 724 KB Output is correct
77 Correct 24 ms 1108 KB Output is correct
78 Correct 22 ms 1100 KB Output is correct
79 Correct 21 ms 1024 KB Output is correct
80 Correct 19 ms 1092 KB Output is correct
81 Correct 20 ms 1096 KB Output is correct
82 Correct 17 ms 1108 KB Output is correct
83 Correct 17 ms 1120 KB Output is correct
84 Correct 16 ms 1036 KB Output is correct
85 Correct 36 ms 1108 KB Output is correct
86 Correct 30 ms 1100 KB Output is correct
87 Correct 28 ms 1060 KB Output is correct
88 Correct 30 ms 1088 KB Output is correct
89 Correct 23 ms 1108 KB Output is correct
90 Correct 22 ms 1024 KB Output is correct
91 Correct 22 ms 1088 KB Output is correct
92 Correct 25 ms 1060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 328 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 328 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 324 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 324 KB Output is correct
62 Correct 1 ms 324 KB Output is correct
63 Correct 1 ms 328 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 9 ms 724 KB Output is correct
66 Correct 7 ms 724 KB Output is correct
67 Correct 7 ms 724 KB Output is correct
68 Correct 8 ms 724 KB Output is correct
69 Correct 12 ms 728 KB Output is correct
70 Correct 9 ms 724 KB Output is correct
71 Correct 10 ms 724 KB Output is correct
72 Correct 10 ms 724 KB Output is correct
73 Correct 8 ms 724 KB Output is correct
74 Correct 8 ms 708 KB Output is correct
75 Correct 8 ms 708 KB Output is correct
76 Correct 8 ms 724 KB Output is correct
77 Correct 24 ms 1108 KB Output is correct
78 Correct 22 ms 1100 KB Output is correct
79 Correct 21 ms 1024 KB Output is correct
80 Correct 19 ms 1092 KB Output is correct
81 Correct 20 ms 1096 KB Output is correct
82 Correct 17 ms 1108 KB Output is correct
83 Correct 17 ms 1120 KB Output is correct
84 Correct 16 ms 1036 KB Output is correct
85 Correct 36 ms 1108 KB Output is correct
86 Correct 30 ms 1100 KB Output is correct
87 Correct 28 ms 1060 KB Output is correct
88 Correct 30 ms 1088 KB Output is correct
89 Correct 23 ms 1108 KB Output is correct
90 Correct 22 ms 1024 KB Output is correct
91 Correct 22 ms 1088 KB Output is correct
92 Correct 25 ms 1060 KB Output is correct
93 Correct 868 ms 6660 KB Output is correct
94 Correct 832 ms 6656 KB Output is correct
95 Correct 812 ms 6472 KB Output is correct
96 Correct 707 ms 6416 KB Output is correct
97 Correct 686 ms 6512 KB Output is correct
98 Correct 698 ms 6688 KB Output is correct
99 Correct 83 ms 1796 KB Output is correct
100 Correct 65 ms 1820 KB Output is correct
101 Correct 60 ms 1796 KB Output is correct
102 Correct 54 ms 1844 KB Output is correct
103 Correct 461 ms 3400 KB Output is correct
104 Correct 278 ms 3312 KB Output is correct
105 Correct 228 ms 3384 KB Output is correct
106 Correct 191 ms 3392 KB Output is correct
107 Correct 1414 ms 6600 KB Output is correct
108 Correct 689 ms 6480 KB Output is correct
109 Correct 557 ms 6472 KB Output is correct
110 Correct 509 ms 6536 KB Output is correct
111 Correct 49 ms 1868 KB Output is correct
112 Correct 47 ms 1872 KB Output is correct
113 Correct 47 ms 1848 KB Output is correct
114 Correct 115 ms 1868 KB Output is correct
115 Correct 84 ms 1868 KB Output is correct
116 Correct 90 ms 1852 KB Output is correct
117 Correct 88 ms 1868 KB Output is correct
118 Correct 71 ms 1856 KB Output is correct
119 Correct 73 ms 1804 KB Output is correct
120 Correct 72 ms 1788 KB Output is correct
121 Correct 68 ms 1772 KB Output is correct
122 Correct 192 ms 3380 KB Output is correct
123 Correct 160 ms 3416 KB Output is correct
124 Correct 145 ms 3372 KB Output is correct
125 Correct 139 ms 3408 KB Output is correct
126 Correct 146 ms 3296 KB Output is correct
127 Correct 123 ms 3372 KB Output is correct
128 Correct 113 ms 3396 KB Output is correct
129 Correct 106 ms 3336 KB Output is correct
130 Correct 136 ms 3396 KB Output is correct
131 Correct 391 ms 3384 KB Output is correct
132 Correct 267 ms 3316 KB Output is correct
133 Correct 241 ms 3528 KB Output is correct
134 Correct 248 ms 3404 KB Output is correct
135 Correct 210 ms 3288 KB Output is correct
136 Correct 198 ms 3552 KB Output is correct
137 Correct 192 ms 3388 KB Output is correct
138 Correct 198 ms 3368 KB Output is correct
139 Correct 182 ms 3280 KB Output is correct
140 Correct 176 ms 3348 KB Output is correct
141 Correct 167 ms 3328 KB Output is correct
142 Correct 407 ms 6640 KB Output is correct
143 Correct 374 ms 6476 KB Output is correct
144 Correct 345 ms 6588 KB Output is correct
145 Correct 322 ms 6448 KB Output is correct
146 Correct 303 ms 6384 KB Output is correct
147 Correct 294 ms 6476 KB Output is correct
148 Correct 411 ms 6476 KB Output is correct
149 Correct 396 ms 6456 KB Output is correct
150 Correct 391 ms 6444 KB Output is correct
151 Correct 463 ms 6468 KB Output is correct
152 Correct 454 ms 6464 KB Output is correct
153 Correct 754 ms 6576 KB Output is correct
154 Correct 683 ms 6604 KB Output is correct
155 Correct 609 ms 6492 KB Output is correct
156 Correct 600 ms 6476 KB Output is correct
157 Correct 654 ms 6476 KB Output is correct
158 Correct 578 ms 6460 KB Output is correct
159 Correct 601 ms 6392 KB Output is correct
160 Correct 508 ms 6536 KB Output is correct
161 Correct 490 ms 6476 KB Output is correct
162 Correct 553 ms 6476 KB Output is correct
163 Correct 484 ms 6476 KB Output is correct
164 Correct 440 ms 6456 KB Output is correct
165 Correct 425 ms 6400 KB Output is correct
166 Correct 413 ms 6432 KB Output is correct
167 Correct 438 ms 6448 KB Output is correct