Submission #579555

# Submission time Handle Problem Language Result Execution time Memory
579555 2022-06-19T11:19:52 Z amunduzbaev Amusement Park (CEOI19_amusementpark) C++17
63 / 100
3000 ms 28236 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
//~ #define int ll
 
const int mod = 119 << 23 | 1;
const int N = 18;
map<int, int> dp[1 << N];
int is[N];
 
int bp(int a, int b){
	int c = 1;
	while(b){
		if(b & 1) c = c * 1ll * a % mod;
		a = a * 1ll * a % mod, b >>= 1;
	} return c;
}
 
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m; cin>>n>>m;
	for(int i=0;i<m;i++){
		int a, b; cin>>a>>b;
		--a, --b;
		is[a] |= (1 << b);
		is[b] |= (1 << a);
	}
	
	dp[0][0] = 1;
	for(int mask=0;mask < (1 << n);mask++){
		for(int j=0;j<n;j++){
			if(mask >> j & 1) continue;
			
			int on_j = mask | (1 << j);
			for(int m2=on_j;m2 < (1 << n); m2++, m2 |= on_j){
				int bad = m2 ^ on_j;
				if(!dp[mask].count(bad)) continue;
				int edge_out = ((1 << n) - 1) ^ (is[j] ^ (is[j] & mask));
				int bad2 = ((bad | ((1 << j) - 1)) ^ (mask & ((1 << j) - 1))) & edge_out;
				int& res = dp[on_j][bad2];
				res = (res + dp[mask][bad]);
				if(res >= mod) res -= mod;
			}
		}
	}
	
	int res = dp[(1 << n) - 1][0];
	//~ cout<<res<<"\n";
	cout<<res * 1ll * bp(2, mod - 2) % mod * m % mod<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12500 KB Output is correct
2 Correct 8 ms 12628 KB Output is correct
3 Correct 8 ms 12628 KB Output is correct
4 Correct 8 ms 12628 KB Output is correct
5 Correct 7 ms 12628 KB Output is correct
6 Correct 8 ms 12628 KB Output is correct
7 Correct 8 ms 12500 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12500 KB Output is correct
2 Correct 8 ms 12628 KB Output is correct
3 Correct 8 ms 12628 KB Output is correct
4 Correct 8 ms 12628 KB Output is correct
5 Correct 7 ms 12628 KB Output is correct
6 Correct 8 ms 12628 KB Output is correct
7 Correct 8 ms 12500 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
9 Correct 8 ms 12628 KB Output is correct
10 Correct 7 ms 12628 KB Output is correct
11 Correct 7 ms 12628 KB Output is correct
12 Correct 8 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 8 ms 12504 KB Output is correct
15 Correct 9 ms 12628 KB Output is correct
16 Correct 7 ms 12624 KB Output is correct
17 Correct 7 ms 12628 KB Output is correct
18 Correct 8 ms 12632 KB Output is correct
19 Correct 7 ms 12612 KB Output is correct
20 Correct 7 ms 12628 KB Output is correct
21 Correct 8 ms 12628 KB Output is correct
22 Correct 7 ms 12632 KB Output is correct
23 Correct 8 ms 12636 KB Output is correct
24 Correct 7 ms 12552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12500 KB Output is correct
2 Correct 8 ms 12628 KB Output is correct
3 Correct 8 ms 12628 KB Output is correct
4 Correct 8 ms 12628 KB Output is correct
5 Correct 7 ms 12628 KB Output is correct
6 Correct 8 ms 12628 KB Output is correct
7 Correct 8 ms 12500 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
9 Correct 8 ms 12628 KB Output is correct
10 Correct 7 ms 12628 KB Output is correct
11 Correct 7 ms 12628 KB Output is correct
12 Correct 8 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 8 ms 12504 KB Output is correct
15 Correct 9 ms 12628 KB Output is correct
16 Correct 7 ms 12624 KB Output is correct
17 Correct 7 ms 12628 KB Output is correct
18 Correct 8 ms 12632 KB Output is correct
19 Correct 7 ms 12612 KB Output is correct
20 Correct 7 ms 12628 KB Output is correct
21 Correct 8 ms 12628 KB Output is correct
22 Correct 7 ms 12632 KB Output is correct
23 Correct 8 ms 12636 KB Output is correct
24 Correct 7 ms 12552 KB Output is correct
25 Correct 6 ms 12628 KB Output is correct
26 Correct 7 ms 12628 KB Output is correct
27 Correct 9 ms 12628 KB Output is correct
28 Correct 7 ms 12628 KB Output is correct
29 Correct 9 ms 12628 KB Output is correct
30 Correct 7 ms 12632 KB Output is correct
31 Correct 7 ms 12588 KB Output is correct
32 Correct 8 ms 12628 KB Output is correct
33 Correct 7 ms 12628 KB Output is correct
34 Correct 9 ms 12628 KB Output is correct
35 Correct 7 ms 12628 KB Output is correct
36 Correct 7 ms 12584 KB Output is correct
37 Correct 7 ms 12628 KB Output is correct
38 Correct 8 ms 12628 KB Output is correct
39 Correct 9 ms 12596 KB Output is correct
40 Correct 9 ms 12628 KB Output is correct
41 Correct 7 ms 12628 KB Output is correct
42 Correct 10 ms 12628 KB Output is correct
43 Correct 8 ms 12628 KB Output is correct
44 Correct 8 ms 12572 KB Output is correct
45 Correct 7 ms 12628 KB Output is correct
46 Correct 7 ms 12628 KB Output is correct
47 Correct 7 ms 12628 KB Output is correct
48 Correct 8 ms 12628 KB Output is correct
49 Correct 10 ms 12628 KB Output is correct
50 Correct 9 ms 12668 KB Output is correct
51 Correct 7 ms 12628 KB Output is correct
52 Correct 7 ms 12628 KB Output is correct
53 Correct 10 ms 12620 KB Output is correct
54 Correct 8 ms 12628 KB Output is correct
55 Correct 10 ms 12744 KB Output is correct
56 Correct 9 ms 12820 KB Output is correct
57 Correct 10 ms 12684 KB Output is correct
58 Correct 10 ms 12628 KB Output is correct
59 Correct 9 ms 12628 KB Output is correct
60 Correct 8 ms 12628 KB Output is correct
61 Correct 9 ms 12628 KB Output is correct
62 Correct 8 ms 12628 KB Output is correct
63 Correct 8 ms 12628 KB Output is correct
64 Correct 8 ms 12740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12500 KB Output is correct
2 Correct 8 ms 12628 KB Output is correct
3 Correct 8 ms 12628 KB Output is correct
4 Correct 8 ms 12628 KB Output is correct
5 Correct 7 ms 12628 KB Output is correct
6 Correct 8 ms 12628 KB Output is correct
7 Correct 8 ms 12500 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
9 Correct 8 ms 12628 KB Output is correct
10 Correct 7 ms 12628 KB Output is correct
11 Correct 7 ms 12628 KB Output is correct
12 Correct 8 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 8 ms 12504 KB Output is correct
15 Correct 9 ms 12628 KB Output is correct
16 Correct 7 ms 12624 KB Output is correct
17 Correct 7 ms 12628 KB Output is correct
18 Correct 8 ms 12632 KB Output is correct
19 Correct 7 ms 12612 KB Output is correct
20 Correct 7 ms 12628 KB Output is correct
21 Correct 8 ms 12628 KB Output is correct
22 Correct 7 ms 12632 KB Output is correct
23 Correct 8 ms 12636 KB Output is correct
24 Correct 7 ms 12552 KB Output is correct
25 Correct 6 ms 12628 KB Output is correct
26 Correct 7 ms 12628 KB Output is correct
27 Correct 9 ms 12628 KB Output is correct
28 Correct 7 ms 12628 KB Output is correct
29 Correct 9 ms 12628 KB Output is correct
30 Correct 7 ms 12632 KB Output is correct
31 Correct 7 ms 12588 KB Output is correct
32 Correct 8 ms 12628 KB Output is correct
33 Correct 7 ms 12628 KB Output is correct
34 Correct 9 ms 12628 KB Output is correct
35 Correct 7 ms 12628 KB Output is correct
36 Correct 7 ms 12584 KB Output is correct
37 Correct 7 ms 12628 KB Output is correct
38 Correct 8 ms 12628 KB Output is correct
39 Correct 9 ms 12596 KB Output is correct
40 Correct 9 ms 12628 KB Output is correct
41 Correct 7 ms 12628 KB Output is correct
42 Correct 10 ms 12628 KB Output is correct
43 Correct 8 ms 12628 KB Output is correct
44 Correct 8 ms 12572 KB Output is correct
45 Correct 7 ms 12628 KB Output is correct
46 Correct 7 ms 12628 KB Output is correct
47 Correct 7 ms 12628 KB Output is correct
48 Correct 8 ms 12628 KB Output is correct
49 Correct 10 ms 12628 KB Output is correct
50 Correct 9 ms 12668 KB Output is correct
51 Correct 7 ms 12628 KB Output is correct
52 Correct 7 ms 12628 KB Output is correct
53 Correct 10 ms 12620 KB Output is correct
54 Correct 8 ms 12628 KB Output is correct
55 Correct 10 ms 12744 KB Output is correct
56 Correct 9 ms 12820 KB Output is correct
57 Correct 10 ms 12684 KB Output is correct
58 Correct 10 ms 12628 KB Output is correct
59 Correct 9 ms 12628 KB Output is correct
60 Correct 8 ms 12628 KB Output is correct
61 Correct 9 ms 12628 KB Output is correct
62 Correct 8 ms 12628 KB Output is correct
63 Correct 8 ms 12628 KB Output is correct
64 Correct 8 ms 12740 KB Output is correct
65 Correct 106 ms 17304 KB Output is correct
66 Correct 191 ms 18752 KB Output is correct
67 Correct 135 ms 18196 KB Output is correct
68 Correct 123 ms 17908 KB Output is correct
69 Correct 88 ms 14436 KB Output is correct
70 Correct 83 ms 14872 KB Output is correct
71 Correct 82 ms 14912 KB Output is correct
72 Correct 86 ms 14932 KB Output is correct
73 Correct 93 ms 15016 KB Output is correct
74 Correct 88 ms 15056 KB Output is correct
75 Correct 83 ms 14984 KB Output is correct
76 Correct 91 ms 15056 KB Output is correct
77 Correct 392 ms 23808 KB Output is correct
78 Correct 328 ms 25048 KB Output is correct
79 Correct 439 ms 28236 KB Output is correct
80 Correct 361 ms 25496 KB Output is correct
81 Correct 410 ms 26636 KB Output is correct
82 Correct 373 ms 25248 KB Output is correct
83 Correct 400 ms 24884 KB Output is correct
84 Correct 353 ms 21420 KB Output is correct
85 Correct 270 ms 16580 KB Output is correct
86 Correct 277 ms 17592 KB Output is correct
87 Correct 295 ms 17512 KB Output is correct
88 Correct 252 ms 17676 KB Output is correct
89 Correct 242 ms 17744 KB Output is correct
90 Correct 252 ms 17744 KB Output is correct
91 Correct 259 ms 17768 KB Output is correct
92 Correct 264 ms 17740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12500 KB Output is correct
2 Correct 8 ms 12628 KB Output is correct
3 Correct 8 ms 12628 KB Output is correct
4 Correct 8 ms 12628 KB Output is correct
5 Correct 7 ms 12628 KB Output is correct
6 Correct 8 ms 12628 KB Output is correct
7 Correct 8 ms 12500 KB Output is correct
8 Correct 7 ms 12628 KB Output is correct
9 Correct 8 ms 12628 KB Output is correct
10 Correct 7 ms 12628 KB Output is correct
11 Correct 7 ms 12628 KB Output is correct
12 Correct 8 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 8 ms 12504 KB Output is correct
15 Correct 9 ms 12628 KB Output is correct
16 Correct 7 ms 12624 KB Output is correct
17 Correct 7 ms 12628 KB Output is correct
18 Correct 8 ms 12632 KB Output is correct
19 Correct 7 ms 12612 KB Output is correct
20 Correct 7 ms 12628 KB Output is correct
21 Correct 8 ms 12628 KB Output is correct
22 Correct 7 ms 12632 KB Output is correct
23 Correct 8 ms 12636 KB Output is correct
24 Correct 7 ms 12552 KB Output is correct
25 Correct 6 ms 12628 KB Output is correct
26 Correct 7 ms 12628 KB Output is correct
27 Correct 9 ms 12628 KB Output is correct
28 Correct 7 ms 12628 KB Output is correct
29 Correct 9 ms 12628 KB Output is correct
30 Correct 7 ms 12632 KB Output is correct
31 Correct 7 ms 12588 KB Output is correct
32 Correct 8 ms 12628 KB Output is correct
33 Correct 7 ms 12628 KB Output is correct
34 Correct 9 ms 12628 KB Output is correct
35 Correct 7 ms 12628 KB Output is correct
36 Correct 7 ms 12584 KB Output is correct
37 Correct 7 ms 12628 KB Output is correct
38 Correct 8 ms 12628 KB Output is correct
39 Correct 9 ms 12596 KB Output is correct
40 Correct 9 ms 12628 KB Output is correct
41 Correct 7 ms 12628 KB Output is correct
42 Correct 10 ms 12628 KB Output is correct
43 Correct 8 ms 12628 KB Output is correct
44 Correct 8 ms 12572 KB Output is correct
45 Correct 7 ms 12628 KB Output is correct
46 Correct 7 ms 12628 KB Output is correct
47 Correct 7 ms 12628 KB Output is correct
48 Correct 8 ms 12628 KB Output is correct
49 Correct 10 ms 12628 KB Output is correct
50 Correct 9 ms 12668 KB Output is correct
51 Correct 7 ms 12628 KB Output is correct
52 Correct 7 ms 12628 KB Output is correct
53 Correct 10 ms 12620 KB Output is correct
54 Correct 8 ms 12628 KB Output is correct
55 Correct 10 ms 12744 KB Output is correct
56 Correct 9 ms 12820 KB Output is correct
57 Correct 10 ms 12684 KB Output is correct
58 Correct 10 ms 12628 KB Output is correct
59 Correct 9 ms 12628 KB Output is correct
60 Correct 8 ms 12628 KB Output is correct
61 Correct 9 ms 12628 KB Output is correct
62 Correct 8 ms 12628 KB Output is correct
63 Correct 8 ms 12628 KB Output is correct
64 Correct 8 ms 12740 KB Output is correct
65 Correct 106 ms 17304 KB Output is correct
66 Correct 191 ms 18752 KB Output is correct
67 Correct 135 ms 18196 KB Output is correct
68 Correct 123 ms 17908 KB Output is correct
69 Correct 88 ms 14436 KB Output is correct
70 Correct 83 ms 14872 KB Output is correct
71 Correct 82 ms 14912 KB Output is correct
72 Correct 86 ms 14932 KB Output is correct
73 Correct 93 ms 15016 KB Output is correct
74 Correct 88 ms 15056 KB Output is correct
75 Correct 83 ms 14984 KB Output is correct
76 Correct 91 ms 15056 KB Output is correct
77 Correct 392 ms 23808 KB Output is correct
78 Correct 328 ms 25048 KB Output is correct
79 Correct 439 ms 28236 KB Output is correct
80 Correct 361 ms 25496 KB Output is correct
81 Correct 410 ms 26636 KB Output is correct
82 Correct 373 ms 25248 KB Output is correct
83 Correct 400 ms 24884 KB Output is correct
84 Correct 353 ms 21420 KB Output is correct
85 Correct 270 ms 16580 KB Output is correct
86 Correct 277 ms 17592 KB Output is correct
87 Correct 295 ms 17512 KB Output is correct
88 Correct 252 ms 17676 KB Output is correct
89 Correct 242 ms 17744 KB Output is correct
90 Correct 252 ms 17744 KB Output is correct
91 Correct 259 ms 17768 KB Output is correct
92 Correct 264 ms 17740 KB Output is correct
93 Execution timed out 3066 ms 25124 KB Time limit exceeded
94 Halted 0 ms 0 KB -