Submission #579554

# Submission time Handle Problem Language Result Execution time Memory
579554 2022-06-19T11:19:32 Z amunduzbaev Amusement Park (CEOI19_amusementpark) C++17
63 / 100
3000 ms 29700 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;
unordered_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 14592 KB Output is correct
2 Correct 9 ms 14676 KB Output is correct
3 Correct 8 ms 14684 KB Output is correct
4 Correct 9 ms 14676 KB Output is correct
5 Correct 9 ms 14664 KB Output is correct
6 Correct 9 ms 14676 KB Output is correct
7 Correct 9 ms 14612 KB Output is correct
8 Correct 9 ms 14676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14592 KB Output is correct
2 Correct 9 ms 14676 KB Output is correct
3 Correct 8 ms 14684 KB Output is correct
4 Correct 9 ms 14676 KB Output is correct
5 Correct 9 ms 14664 KB Output is correct
6 Correct 9 ms 14676 KB Output is correct
7 Correct 9 ms 14612 KB Output is correct
8 Correct 9 ms 14676 KB Output is correct
9 Correct 11 ms 14676 KB Output is correct
10 Correct 10 ms 14600 KB Output is correct
11 Correct 9 ms 14676 KB Output is correct
12 Correct 11 ms 14684 KB Output is correct
13 Correct 9 ms 14684 KB Output is correct
14 Correct 9 ms 14676 KB Output is correct
15 Correct 12 ms 14672 KB Output is correct
16 Correct 8 ms 14676 KB Output is correct
17 Correct 8 ms 14676 KB Output is correct
18 Correct 10 ms 14676 KB Output is correct
19 Correct 11 ms 14676 KB Output is correct
20 Correct 9 ms 14688 KB Output is correct
21 Correct 9 ms 14676 KB Output is correct
22 Correct 9 ms 14676 KB Output is correct
23 Correct 12 ms 14676 KB Output is correct
24 Correct 10 ms 14608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14592 KB Output is correct
2 Correct 9 ms 14676 KB Output is correct
3 Correct 8 ms 14684 KB Output is correct
4 Correct 9 ms 14676 KB Output is correct
5 Correct 9 ms 14664 KB Output is correct
6 Correct 9 ms 14676 KB Output is correct
7 Correct 9 ms 14612 KB Output is correct
8 Correct 9 ms 14676 KB Output is correct
9 Correct 11 ms 14676 KB Output is correct
10 Correct 10 ms 14600 KB Output is correct
11 Correct 9 ms 14676 KB Output is correct
12 Correct 11 ms 14684 KB Output is correct
13 Correct 9 ms 14684 KB Output is correct
14 Correct 9 ms 14676 KB Output is correct
15 Correct 12 ms 14672 KB Output is correct
16 Correct 8 ms 14676 KB Output is correct
17 Correct 8 ms 14676 KB Output is correct
18 Correct 10 ms 14676 KB Output is correct
19 Correct 11 ms 14676 KB Output is correct
20 Correct 9 ms 14688 KB Output is correct
21 Correct 9 ms 14676 KB Output is correct
22 Correct 9 ms 14676 KB Output is correct
23 Correct 12 ms 14676 KB Output is correct
24 Correct 10 ms 14608 KB Output is correct
25 Correct 9 ms 14680 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 8 ms 14656 KB Output is correct
28 Correct 11 ms 14676 KB Output is correct
29 Correct 9 ms 14636 KB Output is correct
30 Correct 8 ms 14676 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 10 ms 14716 KB Output is correct
33 Correct 8 ms 14720 KB Output is correct
34 Correct 8 ms 14676 KB Output is correct
35 Correct 9 ms 14676 KB Output is correct
36 Correct 9 ms 14676 KB Output is correct
37 Correct 9 ms 14676 KB Output is correct
38 Correct 9 ms 14676 KB Output is correct
39 Correct 12 ms 14752 KB Output is correct
40 Correct 10 ms 14676 KB Output is correct
41 Correct 11 ms 14676 KB Output is correct
42 Correct 10 ms 14776 KB Output is correct
43 Correct 10 ms 14720 KB Output is correct
44 Correct 10 ms 14660 KB Output is correct
45 Correct 11 ms 14676 KB Output is correct
46 Correct 9 ms 14676 KB Output is correct
47 Correct 9 ms 14736 KB Output is correct
48 Correct 9 ms 14764 KB Output is correct
49 Correct 9 ms 14676 KB Output is correct
50 Correct 10 ms 14676 KB Output is correct
51 Correct 12 ms 14676 KB Output is correct
52 Correct 12 ms 14820 KB Output is correct
53 Correct 13 ms 14848 KB Output is correct
54 Correct 11 ms 14804 KB Output is correct
55 Correct 11 ms 14824 KB Output is correct
56 Correct 13 ms 14804 KB Output is correct
57 Correct 10 ms 14804 KB Output is correct
58 Correct 11 ms 14760 KB Output is correct
59 Correct 11 ms 14804 KB Output is correct
60 Correct 11 ms 14804 KB Output is correct
61 Correct 12 ms 14776 KB Output is correct
62 Correct 14 ms 14804 KB Output is correct
63 Correct 13 ms 14776 KB Output is correct
64 Correct 11 ms 14808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14592 KB Output is correct
2 Correct 9 ms 14676 KB Output is correct
3 Correct 8 ms 14684 KB Output is correct
4 Correct 9 ms 14676 KB Output is correct
5 Correct 9 ms 14664 KB Output is correct
6 Correct 9 ms 14676 KB Output is correct
7 Correct 9 ms 14612 KB Output is correct
8 Correct 9 ms 14676 KB Output is correct
9 Correct 11 ms 14676 KB Output is correct
10 Correct 10 ms 14600 KB Output is correct
11 Correct 9 ms 14676 KB Output is correct
12 Correct 11 ms 14684 KB Output is correct
13 Correct 9 ms 14684 KB Output is correct
14 Correct 9 ms 14676 KB Output is correct
15 Correct 12 ms 14672 KB Output is correct
16 Correct 8 ms 14676 KB Output is correct
17 Correct 8 ms 14676 KB Output is correct
18 Correct 10 ms 14676 KB Output is correct
19 Correct 11 ms 14676 KB Output is correct
20 Correct 9 ms 14688 KB Output is correct
21 Correct 9 ms 14676 KB Output is correct
22 Correct 9 ms 14676 KB Output is correct
23 Correct 12 ms 14676 KB Output is correct
24 Correct 10 ms 14608 KB Output is correct
25 Correct 9 ms 14680 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 8 ms 14656 KB Output is correct
28 Correct 11 ms 14676 KB Output is correct
29 Correct 9 ms 14636 KB Output is correct
30 Correct 8 ms 14676 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 10 ms 14716 KB Output is correct
33 Correct 8 ms 14720 KB Output is correct
34 Correct 8 ms 14676 KB Output is correct
35 Correct 9 ms 14676 KB Output is correct
36 Correct 9 ms 14676 KB Output is correct
37 Correct 9 ms 14676 KB Output is correct
38 Correct 9 ms 14676 KB Output is correct
39 Correct 12 ms 14752 KB Output is correct
40 Correct 10 ms 14676 KB Output is correct
41 Correct 11 ms 14676 KB Output is correct
42 Correct 10 ms 14776 KB Output is correct
43 Correct 10 ms 14720 KB Output is correct
44 Correct 10 ms 14660 KB Output is correct
45 Correct 11 ms 14676 KB Output is correct
46 Correct 9 ms 14676 KB Output is correct
47 Correct 9 ms 14736 KB Output is correct
48 Correct 9 ms 14764 KB Output is correct
49 Correct 9 ms 14676 KB Output is correct
50 Correct 10 ms 14676 KB Output is correct
51 Correct 12 ms 14676 KB Output is correct
52 Correct 12 ms 14820 KB Output is correct
53 Correct 13 ms 14848 KB Output is correct
54 Correct 11 ms 14804 KB Output is correct
55 Correct 11 ms 14824 KB Output is correct
56 Correct 13 ms 14804 KB Output is correct
57 Correct 10 ms 14804 KB Output is correct
58 Correct 11 ms 14760 KB Output is correct
59 Correct 11 ms 14804 KB Output is correct
60 Correct 11 ms 14804 KB Output is correct
61 Correct 12 ms 14776 KB Output is correct
62 Correct 14 ms 14804 KB Output is correct
63 Correct 13 ms 14776 KB Output is correct
64 Correct 11 ms 14808 KB Output is correct
65 Correct 242 ms 19640 KB Output is correct
66 Correct 281 ms 20648 KB Output is correct
67 Correct 280 ms 20376 KB Output is correct
68 Correct 297 ms 20032 KB Output is correct
69 Correct 203 ms 17684 KB Output is correct
70 Correct 226 ms 18000 KB Output is correct
71 Correct 212 ms 18064 KB Output is correct
72 Correct 209 ms 18036 KB Output is correct
73 Correct 213 ms 18056 KB Output is correct
74 Correct 220 ms 17996 KB Output is correct
75 Correct 221 ms 18228 KB Output is correct
76 Correct 215 ms 17996 KB Output is correct
77 Correct 735 ms 26148 KB Output is correct
78 Correct 771 ms 27196 KB Output is correct
79 Correct 836 ms 29700 KB Output is correct
80 Correct 797 ms 27200 KB Output is correct
81 Correct 833 ms 28304 KB Output is correct
82 Correct 839 ms 27092 KB Output is correct
83 Correct 831 ms 26672 KB Output is correct
84 Correct 846 ms 23968 KB Output is correct
85 Correct 644 ms 20876 KB Output is correct
86 Correct 693 ms 21648 KB Output is correct
87 Correct 691 ms 21584 KB Output is correct
88 Correct 675 ms 21580 KB Output is correct
89 Correct 731 ms 21636 KB Output is correct
90 Correct 702 ms 21708 KB Output is correct
91 Correct 718 ms 21724 KB Output is correct
92 Correct 739 ms 21724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14592 KB Output is correct
2 Correct 9 ms 14676 KB Output is correct
3 Correct 8 ms 14684 KB Output is correct
4 Correct 9 ms 14676 KB Output is correct
5 Correct 9 ms 14664 KB Output is correct
6 Correct 9 ms 14676 KB Output is correct
7 Correct 9 ms 14612 KB Output is correct
8 Correct 9 ms 14676 KB Output is correct
9 Correct 11 ms 14676 KB Output is correct
10 Correct 10 ms 14600 KB Output is correct
11 Correct 9 ms 14676 KB Output is correct
12 Correct 11 ms 14684 KB Output is correct
13 Correct 9 ms 14684 KB Output is correct
14 Correct 9 ms 14676 KB Output is correct
15 Correct 12 ms 14672 KB Output is correct
16 Correct 8 ms 14676 KB Output is correct
17 Correct 8 ms 14676 KB Output is correct
18 Correct 10 ms 14676 KB Output is correct
19 Correct 11 ms 14676 KB Output is correct
20 Correct 9 ms 14688 KB Output is correct
21 Correct 9 ms 14676 KB Output is correct
22 Correct 9 ms 14676 KB Output is correct
23 Correct 12 ms 14676 KB Output is correct
24 Correct 10 ms 14608 KB Output is correct
25 Correct 9 ms 14680 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 8 ms 14656 KB Output is correct
28 Correct 11 ms 14676 KB Output is correct
29 Correct 9 ms 14636 KB Output is correct
30 Correct 8 ms 14676 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 10 ms 14716 KB Output is correct
33 Correct 8 ms 14720 KB Output is correct
34 Correct 8 ms 14676 KB Output is correct
35 Correct 9 ms 14676 KB Output is correct
36 Correct 9 ms 14676 KB Output is correct
37 Correct 9 ms 14676 KB Output is correct
38 Correct 9 ms 14676 KB Output is correct
39 Correct 12 ms 14752 KB Output is correct
40 Correct 10 ms 14676 KB Output is correct
41 Correct 11 ms 14676 KB Output is correct
42 Correct 10 ms 14776 KB Output is correct
43 Correct 10 ms 14720 KB Output is correct
44 Correct 10 ms 14660 KB Output is correct
45 Correct 11 ms 14676 KB Output is correct
46 Correct 9 ms 14676 KB Output is correct
47 Correct 9 ms 14736 KB Output is correct
48 Correct 9 ms 14764 KB Output is correct
49 Correct 9 ms 14676 KB Output is correct
50 Correct 10 ms 14676 KB Output is correct
51 Correct 12 ms 14676 KB Output is correct
52 Correct 12 ms 14820 KB Output is correct
53 Correct 13 ms 14848 KB Output is correct
54 Correct 11 ms 14804 KB Output is correct
55 Correct 11 ms 14824 KB Output is correct
56 Correct 13 ms 14804 KB Output is correct
57 Correct 10 ms 14804 KB Output is correct
58 Correct 11 ms 14760 KB Output is correct
59 Correct 11 ms 14804 KB Output is correct
60 Correct 11 ms 14804 KB Output is correct
61 Correct 12 ms 14776 KB Output is correct
62 Correct 14 ms 14804 KB Output is correct
63 Correct 13 ms 14776 KB Output is correct
64 Correct 11 ms 14808 KB Output is correct
65 Correct 242 ms 19640 KB Output is correct
66 Correct 281 ms 20648 KB Output is correct
67 Correct 280 ms 20376 KB Output is correct
68 Correct 297 ms 20032 KB Output is correct
69 Correct 203 ms 17684 KB Output is correct
70 Correct 226 ms 18000 KB Output is correct
71 Correct 212 ms 18064 KB Output is correct
72 Correct 209 ms 18036 KB Output is correct
73 Correct 213 ms 18056 KB Output is correct
74 Correct 220 ms 17996 KB Output is correct
75 Correct 221 ms 18228 KB Output is correct
76 Correct 215 ms 17996 KB Output is correct
77 Correct 735 ms 26148 KB Output is correct
78 Correct 771 ms 27196 KB Output is correct
79 Correct 836 ms 29700 KB Output is correct
80 Correct 797 ms 27200 KB Output is correct
81 Correct 833 ms 28304 KB Output is correct
82 Correct 839 ms 27092 KB Output is correct
83 Correct 831 ms 26672 KB Output is correct
84 Correct 846 ms 23968 KB Output is correct
85 Correct 644 ms 20876 KB Output is correct
86 Correct 693 ms 21648 KB Output is correct
87 Correct 691 ms 21584 KB Output is correct
88 Correct 675 ms 21580 KB Output is correct
89 Correct 731 ms 21636 KB Output is correct
90 Correct 702 ms 21708 KB Output is correct
91 Correct 718 ms 21724 KB Output is correct
92 Correct 739 ms 21724 KB Output is correct
93 Execution timed out 3031 ms 20816 KB Time limit exceeded
94 Halted 0 ms 0 KB -