Submission #579551

# Submission time Handle Problem Language Result Execution time Memory
579551 2022-06-19T11:14:56 Z amunduzbaev Amusement Park (CEOI19_amusementpark) C++17
63 / 100
3000 ms 29424 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;
				dp[on_j][bad2] = (dp[on_j][bad2] + dp[mask][bad]) % mod;
				//~ for(int i=0;i<n;i++) cout<<(mask >> i & 1);
				//~ cout<<"\n";
				//~ for(int i=0;i<n;i++) cout<<(bad >> i & 1);
				//~ cout<<"\n";

				//~ for(int i=0;i<n;i++) cout<<(on_j >> i & 1);
				//~ cout<<"\n";
				//~ for(int i=0;i<n;i++) cout<<(bad2 >> i & 1);
				//~ cout<<"\n";
				//~ cout<<"\n";
			}
		}
	}
	
	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 7 ms 12628 KB Output is correct
2 Correct 7 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 7 ms 12628 KB Output is correct
5 Correct 9 ms 12628 KB Output is correct
6 Correct 7 ms 12628 KB Output is correct
7 Correct 7 ms 12628 KB Output is correct
8 Correct 6 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12628 KB Output is correct
2 Correct 7 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 7 ms 12628 KB Output is correct
5 Correct 9 ms 12628 KB Output is correct
6 Correct 7 ms 12628 KB Output is correct
7 Correct 7 ms 12628 KB Output is correct
8 Correct 6 ms 12628 KB Output is correct
9 Correct 7 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 7 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 7 ms 12544 KB Output is correct
15 Correct 6 ms 12504 KB Output is correct
16 Correct 7 ms 12620 KB Output is correct
17 Correct 7 ms 12628 KB Output is correct
18 Correct 8 ms 12628 KB Output is correct
19 Correct 7 ms 12624 KB Output is correct
20 Correct 6 ms 12628 KB Output is correct
21 Correct 7 ms 12628 KB Output is correct
22 Correct 6 ms 12628 KB Output is correct
23 Correct 8 ms 12628 KB Output is correct
24 Correct 7 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12628 KB Output is correct
2 Correct 7 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 7 ms 12628 KB Output is correct
5 Correct 9 ms 12628 KB Output is correct
6 Correct 7 ms 12628 KB Output is correct
7 Correct 7 ms 12628 KB Output is correct
8 Correct 6 ms 12628 KB Output is correct
9 Correct 7 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 7 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 7 ms 12544 KB Output is correct
15 Correct 6 ms 12504 KB Output is correct
16 Correct 7 ms 12620 KB Output is correct
17 Correct 7 ms 12628 KB Output is correct
18 Correct 8 ms 12628 KB Output is correct
19 Correct 7 ms 12624 KB Output is correct
20 Correct 6 ms 12628 KB Output is correct
21 Correct 7 ms 12628 KB Output is correct
22 Correct 6 ms 12628 KB Output is correct
23 Correct 8 ms 12628 KB Output is correct
24 Correct 7 ms 12628 KB Output is correct
25 Correct 6 ms 12628 KB Output is correct
26 Correct 7 ms 12632 KB Output is correct
27 Correct 7 ms 12628 KB Output is correct
28 Correct 7 ms 12536 KB Output is correct
29 Correct 7 ms 12628 KB Output is correct
30 Correct 7 ms 12628 KB Output is correct
31 Correct 7 ms 12628 KB Output is correct
32 Correct 8 ms 12628 KB Output is correct
33 Correct 7 ms 12648 KB Output is correct
34 Correct 8 ms 12632 KB Output is correct
35 Correct 7 ms 12628 KB Output is correct
36 Correct 7 ms 12628 KB Output is correct
37 Correct 7 ms 12628 KB Output is correct
38 Correct 9 ms 12520 KB Output is correct
39 Correct 9 ms 12628 KB Output is correct
40 Correct 7 ms 12628 KB Output is correct
41 Correct 8 ms 12632 KB Output is correct
42 Correct 8 ms 12628 KB Output is correct
43 Correct 7 ms 12628 KB Output is correct
44 Correct 7 ms 12632 KB Output is correct
45 Correct 8 ms 12632 KB Output is correct
46 Correct 7 ms 12628 KB Output is correct
47 Correct 8 ms 12628 KB Output is correct
48 Correct 8 ms 12628 KB Output is correct
49 Correct 7 ms 12588 KB Output is correct
50 Correct 8 ms 12632 KB Output is correct
51 Correct 8 ms 12628 KB Output is correct
52 Correct 8 ms 12668 KB Output is correct
53 Correct 8 ms 12720 KB Output is correct
54 Correct 9 ms 12756 KB Output is correct
55 Correct 8 ms 12628 KB Output is correct
56 Correct 11 ms 12760 KB Output is correct
57 Correct 9 ms 12756 KB Output is correct
58 Correct 8 ms 12756 KB Output is correct
59 Correct 7 ms 12628 KB Output is correct
60 Correct 7 ms 12628 KB Output is correct
61 Correct 8 ms 12628 KB Output is correct
62 Correct 8 ms 12628 KB Output is correct
63 Correct 8 ms 12632 KB Output is correct
64 Correct 8 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12628 KB Output is correct
2 Correct 7 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 7 ms 12628 KB Output is correct
5 Correct 9 ms 12628 KB Output is correct
6 Correct 7 ms 12628 KB Output is correct
7 Correct 7 ms 12628 KB Output is correct
8 Correct 6 ms 12628 KB Output is correct
9 Correct 7 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 7 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 7 ms 12544 KB Output is correct
15 Correct 6 ms 12504 KB Output is correct
16 Correct 7 ms 12620 KB Output is correct
17 Correct 7 ms 12628 KB Output is correct
18 Correct 8 ms 12628 KB Output is correct
19 Correct 7 ms 12624 KB Output is correct
20 Correct 6 ms 12628 KB Output is correct
21 Correct 7 ms 12628 KB Output is correct
22 Correct 6 ms 12628 KB Output is correct
23 Correct 8 ms 12628 KB Output is correct
24 Correct 7 ms 12628 KB Output is correct
25 Correct 6 ms 12628 KB Output is correct
26 Correct 7 ms 12632 KB Output is correct
27 Correct 7 ms 12628 KB Output is correct
28 Correct 7 ms 12536 KB Output is correct
29 Correct 7 ms 12628 KB Output is correct
30 Correct 7 ms 12628 KB Output is correct
31 Correct 7 ms 12628 KB Output is correct
32 Correct 8 ms 12628 KB Output is correct
33 Correct 7 ms 12648 KB Output is correct
34 Correct 8 ms 12632 KB Output is correct
35 Correct 7 ms 12628 KB Output is correct
36 Correct 7 ms 12628 KB Output is correct
37 Correct 7 ms 12628 KB Output is correct
38 Correct 9 ms 12520 KB Output is correct
39 Correct 9 ms 12628 KB Output is correct
40 Correct 7 ms 12628 KB Output is correct
41 Correct 8 ms 12632 KB Output is correct
42 Correct 8 ms 12628 KB Output is correct
43 Correct 7 ms 12628 KB Output is correct
44 Correct 7 ms 12632 KB Output is correct
45 Correct 8 ms 12632 KB Output is correct
46 Correct 7 ms 12628 KB Output is correct
47 Correct 8 ms 12628 KB Output is correct
48 Correct 8 ms 12628 KB Output is correct
49 Correct 7 ms 12588 KB Output is correct
50 Correct 8 ms 12632 KB Output is correct
51 Correct 8 ms 12628 KB Output is correct
52 Correct 8 ms 12668 KB Output is correct
53 Correct 8 ms 12720 KB Output is correct
54 Correct 9 ms 12756 KB Output is correct
55 Correct 8 ms 12628 KB Output is correct
56 Correct 11 ms 12760 KB Output is correct
57 Correct 9 ms 12756 KB Output is correct
58 Correct 8 ms 12756 KB Output is correct
59 Correct 7 ms 12628 KB Output is correct
60 Correct 7 ms 12628 KB Output is correct
61 Correct 8 ms 12628 KB Output is correct
62 Correct 8 ms 12628 KB Output is correct
63 Correct 8 ms 12632 KB Output is correct
64 Correct 8 ms 12628 KB Output is correct
65 Correct 114 ms 17364 KB Output is correct
66 Correct 139 ms 18816 KB Output is correct
67 Correct 128 ms 18216 KB Output is correct
68 Correct 128 ms 18032 KB Output is correct
69 Correct 90 ms 14516 KB Output is correct
70 Correct 78 ms 14944 KB Output is correct
71 Correct 87 ms 14964 KB Output is correct
72 Correct 77 ms 14956 KB Output is correct
73 Correct 107 ms 15000 KB Output is correct
74 Correct 87 ms 14992 KB Output is correct
75 Correct 79 ms 14940 KB Output is correct
76 Correct 82 ms 15040 KB Output is correct
77 Correct 324 ms 23916 KB Output is correct
78 Correct 341 ms 25112 KB Output is correct
79 Correct 434 ms 28352 KB Output is correct
80 Correct 379 ms 25484 KB Output is correct
81 Correct 403 ms 26908 KB Output is correct
82 Correct 377 ms 25292 KB Output is correct
83 Correct 404 ms 24912 KB Output is correct
84 Correct 304 ms 21228 KB Output is correct
85 Correct 195 ms 16652 KB Output is correct
86 Correct 253 ms 17556 KB Output is correct
87 Correct 230 ms 17532 KB Output is correct
88 Correct 225 ms 17620 KB Output is correct
89 Correct 246 ms 17784 KB Output is correct
90 Correct 233 ms 17812 KB Output is correct
91 Correct 231 ms 17900 KB Output is correct
92 Correct 243 ms 17808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12628 KB Output is correct
2 Correct 7 ms 12628 KB Output is correct
3 Correct 7 ms 12628 KB Output is correct
4 Correct 7 ms 12628 KB Output is correct
5 Correct 9 ms 12628 KB Output is correct
6 Correct 7 ms 12628 KB Output is correct
7 Correct 7 ms 12628 KB Output is correct
8 Correct 6 ms 12628 KB Output is correct
9 Correct 7 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 7 ms 12628 KB Output is correct
13 Correct 6 ms 12628 KB Output is correct
14 Correct 7 ms 12544 KB Output is correct
15 Correct 6 ms 12504 KB Output is correct
16 Correct 7 ms 12620 KB Output is correct
17 Correct 7 ms 12628 KB Output is correct
18 Correct 8 ms 12628 KB Output is correct
19 Correct 7 ms 12624 KB Output is correct
20 Correct 6 ms 12628 KB Output is correct
21 Correct 7 ms 12628 KB Output is correct
22 Correct 6 ms 12628 KB Output is correct
23 Correct 8 ms 12628 KB Output is correct
24 Correct 7 ms 12628 KB Output is correct
25 Correct 6 ms 12628 KB Output is correct
26 Correct 7 ms 12632 KB Output is correct
27 Correct 7 ms 12628 KB Output is correct
28 Correct 7 ms 12536 KB Output is correct
29 Correct 7 ms 12628 KB Output is correct
30 Correct 7 ms 12628 KB Output is correct
31 Correct 7 ms 12628 KB Output is correct
32 Correct 8 ms 12628 KB Output is correct
33 Correct 7 ms 12648 KB Output is correct
34 Correct 8 ms 12632 KB Output is correct
35 Correct 7 ms 12628 KB Output is correct
36 Correct 7 ms 12628 KB Output is correct
37 Correct 7 ms 12628 KB Output is correct
38 Correct 9 ms 12520 KB Output is correct
39 Correct 9 ms 12628 KB Output is correct
40 Correct 7 ms 12628 KB Output is correct
41 Correct 8 ms 12632 KB Output is correct
42 Correct 8 ms 12628 KB Output is correct
43 Correct 7 ms 12628 KB Output is correct
44 Correct 7 ms 12632 KB Output is correct
45 Correct 8 ms 12632 KB Output is correct
46 Correct 7 ms 12628 KB Output is correct
47 Correct 8 ms 12628 KB Output is correct
48 Correct 8 ms 12628 KB Output is correct
49 Correct 7 ms 12588 KB Output is correct
50 Correct 8 ms 12632 KB Output is correct
51 Correct 8 ms 12628 KB Output is correct
52 Correct 8 ms 12668 KB Output is correct
53 Correct 8 ms 12720 KB Output is correct
54 Correct 9 ms 12756 KB Output is correct
55 Correct 8 ms 12628 KB Output is correct
56 Correct 11 ms 12760 KB Output is correct
57 Correct 9 ms 12756 KB Output is correct
58 Correct 8 ms 12756 KB Output is correct
59 Correct 7 ms 12628 KB Output is correct
60 Correct 7 ms 12628 KB Output is correct
61 Correct 8 ms 12628 KB Output is correct
62 Correct 8 ms 12628 KB Output is correct
63 Correct 8 ms 12632 KB Output is correct
64 Correct 8 ms 12628 KB Output is correct
65 Correct 114 ms 17364 KB Output is correct
66 Correct 139 ms 18816 KB Output is correct
67 Correct 128 ms 18216 KB Output is correct
68 Correct 128 ms 18032 KB Output is correct
69 Correct 90 ms 14516 KB Output is correct
70 Correct 78 ms 14944 KB Output is correct
71 Correct 87 ms 14964 KB Output is correct
72 Correct 77 ms 14956 KB Output is correct
73 Correct 107 ms 15000 KB Output is correct
74 Correct 87 ms 14992 KB Output is correct
75 Correct 79 ms 14940 KB Output is correct
76 Correct 82 ms 15040 KB Output is correct
77 Correct 324 ms 23916 KB Output is correct
78 Correct 341 ms 25112 KB Output is correct
79 Correct 434 ms 28352 KB Output is correct
80 Correct 379 ms 25484 KB Output is correct
81 Correct 403 ms 26908 KB Output is correct
82 Correct 377 ms 25292 KB Output is correct
83 Correct 404 ms 24912 KB Output is correct
84 Correct 304 ms 21228 KB Output is correct
85 Correct 195 ms 16652 KB Output is correct
86 Correct 253 ms 17556 KB Output is correct
87 Correct 230 ms 17532 KB Output is correct
88 Correct 225 ms 17620 KB Output is correct
89 Correct 246 ms 17784 KB Output is correct
90 Correct 233 ms 17812 KB Output is correct
91 Correct 231 ms 17900 KB Output is correct
92 Correct 243 ms 17808 KB Output is correct
93 Execution timed out 3057 ms 29424 KB Time limit exceeded
94 Halted 0 ms 0 KB -