Submission #379383

# Submission time Handle Problem Language Result Execution time Memory
379383 2021-03-18T05:31:06 Z cheissmart Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 18904 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 20;

int a[1 << 20], sub[1 << N], sup[1 << N];

signed main()
{
	IO_OP;
	
	int l, q;
	cin >> l >> q;
	for(int i = 0; i < (1 << l); i++) {
		char c;
		cin >> c;
		a[i] = c - '0';
	}
	memcpy(sub, a, sizeof(a[0]) * (1 << l));
	memcpy(sup, a, sizeof(a[0]) * (1 << l));
	for(int j = 0; j < l; j++) {
		for(int i = 0; i < (1 << l); i++)
			if(i >> j & 1)
				sub[i] += sub[i ^ (1 << j)];
	}
	for(int j = 0; j < l; j++) {
		for(int i = 0; i < (1 << l); i++)
			if(i >> j & 1)
				sup[i ^ (1 << j)] += sup[i];
	}
	while(q--) {
		string s;
		cin >> s;
		reverse(ALL(s));
		vi one, zero, any;
		for(int i = 0; i < l; i++) {
			if(s[i] == '1') one.PB(i);
			else if(s[i] == '0') zero.PB(i);
			else any.PB(i);
		}
		int m1 = 0, m2 = 0;
		for(int i = 0; i < l; i++) {
			if(s[i] == '?') m2 |= 1 << i;
			else m1 |= (s[i] - '0') << i;
		}
		int mn = min({int(one.size()), int(zero.size()), int(any.size())});
		if(int(one.size()) == mn) {
			int ans = 0;
			for(int m = m1; ; m = (m - 1) & m1) {
				int sign = (__builtin_popcount(m ^ m1) % 2 ? -1 : 1);
				ans += sign * sub[m | m2];
				if(m == 0) break;
			}
			cout << ans << '\n';			
		} else if(int(zero.size()) == mn) {
			int ans = 0;
			int all = ((1 << l) - 1) ^ m2;
			m1 ^= all;
			for(int m = m1; ; m = (m - 1) & m1) {
				int mm = all ^ m;
				int sign = (__builtin_popcount(m ^ m1) % 2 ? -1 : 1);
				ans += sign * sup[mm];
				if(m == 0) break;
			}
			cout << ans << '\n';
		} else {
			int ans = 0;
			for(int m = m2; ; m = (m - 1) & m2) {
				ans += a[m1 | m];
				if(m == 0) break;
			}
			cout << ans << '\n';
		}
	}

}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 581 ms 9324 KB Output is correct
12 Correct 585 ms 8812 KB Output is correct
13 Correct 633 ms 8044 KB Output is correct
14 Correct 670 ms 8172 KB Output is correct
15 Correct 614 ms 9196 KB Output is correct
16 Correct 695 ms 8500 KB Output is correct
17 Correct 675 ms 8276 KB Output is correct
18 Correct 466 ms 10220 KB Output is correct
19 Correct 554 ms 7152 KB Output is correct
20 Correct 582 ms 8868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 581 ms 9324 KB Output is correct
12 Correct 585 ms 8812 KB Output is correct
13 Correct 633 ms 8044 KB Output is correct
14 Correct 670 ms 8172 KB Output is correct
15 Correct 614 ms 9196 KB Output is correct
16 Correct 695 ms 8500 KB Output is correct
17 Correct 675 ms 8276 KB Output is correct
18 Correct 466 ms 10220 KB Output is correct
19 Correct 554 ms 7152 KB Output is correct
20 Correct 582 ms 8868 KB Output is correct
21 Correct 667 ms 8976 KB Output is correct
22 Correct 726 ms 9068 KB Output is correct
23 Correct 736 ms 8044 KB Output is correct
24 Correct 824 ms 7856 KB Output is correct
25 Correct 728 ms 9560 KB Output is correct
26 Correct 826 ms 8048 KB Output is correct
27 Correct 840 ms 7884 KB Output is correct
28 Correct 428 ms 10636 KB Output is correct
29 Correct 585 ms 6480 KB Output is correct
30 Correct 676 ms 8740 KB Output is correct
31 Correct 786 ms 8556 KB Output is correct
32 Correct 840 ms 8684 KB Output is correct
33 Correct 690 ms 7480 KB Output is correct
34 Correct 810 ms 7476 KB Output is correct
35 Correct 815 ms 7828 KB Output is correct
36 Correct 419 ms 6304 KB Output is correct
37 Correct 639 ms 8552 KB Output is correct
38 Correct 618 ms 6380 KB Output is correct
39 Correct 801 ms 7552 KB Output is correct
40 Correct 824 ms 7148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 118 ms 15032 KB Output is correct
12 Correct 118 ms 14924 KB Output is correct
13 Correct 155 ms 14828 KB Output is correct
14 Correct 157 ms 14920 KB Output is correct
15 Correct 119 ms 14956 KB Output is correct
16 Correct 199 ms 14956 KB Output is correct
17 Correct 157 ms 14956 KB Output is correct
18 Correct 92 ms 15084 KB Output is correct
19 Correct 107 ms 14828 KB Output is correct
20 Correct 124 ms 14956 KB Output is correct
21 Correct 144 ms 14956 KB Output is correct
22 Correct 156 ms 14952 KB Output is correct
23 Correct 132 ms 14828 KB Output is correct
24 Correct 173 ms 14956 KB Output is correct
25 Correct 152 ms 14936 KB Output is correct
26 Correct 97 ms 14828 KB Output is correct
27 Correct 113 ms 14956 KB Output is correct
28 Correct 124 ms 14736 KB Output is correct
29 Correct 140 ms 15084 KB Output is correct
30 Correct 138 ms 14956 KB Output is correct
31 Correct 141 ms 14872 KB Output is correct
32 Correct 167 ms 14884 KB Output is correct
33 Correct 156 ms 14956 KB Output is correct
34 Correct 91 ms 14828 KB Output is correct
35 Correct 143 ms 14976 KB Output is correct
36 Correct 135 ms 14956 KB Output is correct
37 Correct 141 ms 14956 KB Output is correct
38 Correct 151 ms 15084 KB Output is correct
39 Correct 160 ms 15084 KB Output is correct
40 Correct 155 ms 14956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 581 ms 9324 KB Output is correct
12 Correct 585 ms 8812 KB Output is correct
13 Correct 633 ms 8044 KB Output is correct
14 Correct 670 ms 8172 KB Output is correct
15 Correct 614 ms 9196 KB Output is correct
16 Correct 695 ms 8500 KB Output is correct
17 Correct 675 ms 8276 KB Output is correct
18 Correct 466 ms 10220 KB Output is correct
19 Correct 554 ms 7152 KB Output is correct
20 Correct 582 ms 8868 KB Output is correct
21 Correct 667 ms 8976 KB Output is correct
22 Correct 726 ms 9068 KB Output is correct
23 Correct 736 ms 8044 KB Output is correct
24 Correct 824 ms 7856 KB Output is correct
25 Correct 728 ms 9560 KB Output is correct
26 Correct 826 ms 8048 KB Output is correct
27 Correct 840 ms 7884 KB Output is correct
28 Correct 428 ms 10636 KB Output is correct
29 Correct 585 ms 6480 KB Output is correct
30 Correct 676 ms 8740 KB Output is correct
31 Correct 786 ms 8556 KB Output is correct
32 Correct 840 ms 8684 KB Output is correct
33 Correct 690 ms 7480 KB Output is correct
34 Correct 810 ms 7476 KB Output is correct
35 Correct 815 ms 7828 KB Output is correct
36 Correct 419 ms 6304 KB Output is correct
37 Correct 639 ms 8552 KB Output is correct
38 Correct 618 ms 6380 KB Output is correct
39 Correct 801 ms 7552 KB Output is correct
40 Correct 824 ms 7148 KB Output is correct
41 Correct 118 ms 15032 KB Output is correct
42 Correct 118 ms 14924 KB Output is correct
43 Correct 155 ms 14828 KB Output is correct
44 Correct 157 ms 14920 KB Output is correct
45 Correct 119 ms 14956 KB Output is correct
46 Correct 199 ms 14956 KB Output is correct
47 Correct 157 ms 14956 KB Output is correct
48 Correct 92 ms 15084 KB Output is correct
49 Correct 107 ms 14828 KB Output is correct
50 Correct 124 ms 14956 KB Output is correct
51 Correct 144 ms 14956 KB Output is correct
52 Correct 156 ms 14952 KB Output is correct
53 Correct 132 ms 14828 KB Output is correct
54 Correct 173 ms 14956 KB Output is correct
55 Correct 152 ms 14936 KB Output is correct
56 Correct 97 ms 14828 KB Output is correct
57 Correct 113 ms 14956 KB Output is correct
58 Correct 124 ms 14736 KB Output is correct
59 Correct 140 ms 15084 KB Output is correct
60 Correct 138 ms 14956 KB Output is correct
61 Correct 141 ms 14872 KB Output is correct
62 Correct 167 ms 14884 KB Output is correct
63 Correct 156 ms 14956 KB Output is correct
64 Correct 91 ms 14828 KB Output is correct
65 Correct 143 ms 14976 KB Output is correct
66 Correct 135 ms 14956 KB Output is correct
67 Correct 141 ms 14956 KB Output is correct
68 Correct 151 ms 15084 KB Output is correct
69 Correct 160 ms 15084 KB Output is correct
70 Correct 155 ms 14956 KB Output is correct
71 Correct 1022 ms 17900 KB Output is correct
72 Correct 1116 ms 17972 KB Output is correct
73 Correct 1368 ms 16516 KB Output is correct
74 Correct 1812 ms 16780 KB Output is correct
75 Correct 1175 ms 18904 KB Output is correct
76 Execution timed out 2069 ms 16876 KB Time limit exceeded
77 Halted 0 ms 0 KB -