Submission #234942

# Submission time Handle Problem Language Result Execution time Memory
234942 2020-05-26T11:47:24 Z amoo_safar Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
863 ms 20688 KB
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 20;

int s1[(1 << Log) + 2];
int s0[(1 << Log) + 2];
int L, Q;
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> L >> Q;
	str s, t;
	cin >> s;
	t = s;
	for(int i = 0; i < (1 << L); i++) s1[i] = s[i] - '0';
	for(int i = 0; i < (1 << L); i++) s0[((1<<L) - 1) ^ i] = s[i] - '0';
	for(int l = 0; l < L; l++)
		for(int i = 0; i < (1 << L); i++)
			if(i >> l & 1) s1[i ^ (1 << l)] += s1[i];
	for(int l = 0; l < L; l++)
		for(int i = 0; i < (1 << L); i++)
			if(i >> l & 1) s0[i ^ (1 << l)] += s0[i];

	while(Q --){

		cin >> s;
		int mk0 = 0, mk1 = 0, mkq = 0;
		int c0 = 0, c1 = 0, cq = 0;
		for(int i = 0; i < L; i++){
			if(s[i] == '1') mk1 |= (1 << (L - 1 - i)), c1 ++;
			if(s[i] == '0') mk0 |= (1 << (L - 1 - i)), c0 ++;
			if(s[i] == '?') mkq |= (1 << (L - 1 - i)), cq ++;
		}
		if(cq <= min(c0, c1)){
			int res = t[mk1]-'0';
			int sub = mkq;
			while(sub){
				res += t[sub + mk1] - '0';
				sub = mkq & (sub - 1);
			}
			cout << res << '\n';
			continue;
		}
		if(c0 <= c1){
			int res = s1[mk1];
			int sub = mk0;
			while(sub){
				res += (__builtin_popcount(sub) & 1 ? -1 : 1) * s1[sub + mk1];
				sub = mk0 & (sub - 1);
			}
			cout << res << '\n';
		} else {
			int res = s0[mk0];
			int sub = mk1;
			while(sub){
				res += (__builtin_popcount(sub) & 1 ? -1 : 1) * s0[sub + mk0];
				sub = mk1 & (sub - 1);
			}
			cout << res << '\n';
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 226 ms 9476 KB Output is correct
12 Correct 235 ms 9160 KB Output is correct
13 Correct 250 ms 8440 KB Output is correct
14 Correct 240 ms 8560 KB Output is correct
15 Correct 239 ms 9464 KB Output is correct
16 Correct 279 ms 8696 KB Output is correct
17 Correct 280 ms 8800 KB Output is correct
18 Correct 185 ms 10492 KB Output is correct
19 Correct 216 ms 7608 KB Output is correct
20 Correct 232 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 226 ms 9476 KB Output is correct
12 Correct 235 ms 9160 KB Output is correct
13 Correct 250 ms 8440 KB Output is correct
14 Correct 240 ms 8560 KB Output is correct
15 Correct 239 ms 9464 KB Output is correct
16 Correct 279 ms 8696 KB Output is correct
17 Correct 280 ms 8800 KB Output is correct
18 Correct 185 ms 10492 KB Output is correct
19 Correct 216 ms 7608 KB Output is correct
20 Correct 232 ms 9208 KB Output is correct
21 Correct 245 ms 9464 KB Output is correct
22 Correct 259 ms 9592 KB Output is correct
23 Correct 294 ms 8568 KB Output is correct
24 Correct 290 ms 8440 KB Output is correct
25 Correct 272 ms 10360 KB Output is correct
26 Correct 334 ms 8952 KB Output is correct
27 Correct 328 ms 8872 KB Output is correct
28 Correct 211 ms 11256 KB Output is correct
29 Correct 236 ms 7160 KB Output is correct
30 Correct 266 ms 9464 KB Output is correct
31 Correct 304 ms 9208 KB Output is correct
32 Correct 344 ms 9208 KB Output is correct
33 Correct 275 ms 8016 KB Output is correct
34 Correct 305 ms 8184 KB Output is correct
35 Correct 323 ms 8440 KB Output is correct
36 Correct 172 ms 6908 KB Output is correct
37 Correct 244 ms 8952 KB Output is correct
38 Correct 248 ms 6904 KB Output is correct
39 Correct 307 ms 7928 KB Output is correct
40 Correct 294 ms 7800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 83 ms 13080 KB Output is correct
12 Correct 77 ms 13080 KB Output is correct
13 Correct 80 ms 12952 KB Output is correct
14 Correct 96 ms 12948 KB Output is correct
15 Correct 75 ms 13076 KB Output is correct
16 Correct 100 ms 12956 KB Output is correct
17 Correct 99 ms 12956 KB Output is correct
18 Correct 71 ms 13336 KB Output is correct
19 Correct 73 ms 12952 KB Output is correct
20 Correct 75 ms 13080 KB Output is correct
21 Correct 85 ms 13080 KB Output is correct
22 Correct 105 ms 12952 KB Output is correct
23 Correct 79 ms 12952 KB Output is correct
24 Correct 86 ms 13080 KB Output is correct
25 Correct 98 ms 12956 KB Output is correct
26 Correct 67 ms 12948 KB Output is correct
27 Correct 75 ms 13080 KB Output is correct
28 Correct 75 ms 12824 KB Output is correct
29 Correct 82 ms 13080 KB Output is correct
30 Correct 85 ms 13080 KB Output is correct
31 Correct 77 ms 12956 KB Output is correct
32 Correct 103 ms 12956 KB Output is correct
33 Correct 92 ms 12952 KB Output is correct
34 Correct 66 ms 12824 KB Output is correct
35 Correct 85 ms 12956 KB Output is correct
36 Correct 86 ms 12952 KB Output is correct
37 Correct 88 ms 12952 KB Output is correct
38 Correct 88 ms 13080 KB Output is correct
39 Correct 90 ms 12928 KB Output is correct
40 Correct 90 ms 12952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 226 ms 9476 KB Output is correct
12 Correct 235 ms 9160 KB Output is correct
13 Correct 250 ms 8440 KB Output is correct
14 Correct 240 ms 8560 KB Output is correct
15 Correct 239 ms 9464 KB Output is correct
16 Correct 279 ms 8696 KB Output is correct
17 Correct 280 ms 8800 KB Output is correct
18 Correct 185 ms 10492 KB Output is correct
19 Correct 216 ms 7608 KB Output is correct
20 Correct 232 ms 9208 KB Output is correct
21 Correct 245 ms 9464 KB Output is correct
22 Correct 259 ms 9592 KB Output is correct
23 Correct 294 ms 8568 KB Output is correct
24 Correct 290 ms 8440 KB Output is correct
25 Correct 272 ms 10360 KB Output is correct
26 Correct 334 ms 8952 KB Output is correct
27 Correct 328 ms 8872 KB Output is correct
28 Correct 211 ms 11256 KB Output is correct
29 Correct 236 ms 7160 KB Output is correct
30 Correct 266 ms 9464 KB Output is correct
31 Correct 304 ms 9208 KB Output is correct
32 Correct 344 ms 9208 KB Output is correct
33 Correct 275 ms 8016 KB Output is correct
34 Correct 305 ms 8184 KB Output is correct
35 Correct 323 ms 8440 KB Output is correct
36 Correct 172 ms 6908 KB Output is correct
37 Correct 244 ms 8952 KB Output is correct
38 Correct 248 ms 6904 KB Output is correct
39 Correct 307 ms 7928 KB Output is correct
40 Correct 294 ms 7800 KB Output is correct
41 Correct 83 ms 13080 KB Output is correct
42 Correct 77 ms 13080 KB Output is correct
43 Correct 80 ms 12952 KB Output is correct
44 Correct 96 ms 12948 KB Output is correct
45 Correct 75 ms 13076 KB Output is correct
46 Correct 100 ms 12956 KB Output is correct
47 Correct 99 ms 12956 KB Output is correct
48 Correct 71 ms 13336 KB Output is correct
49 Correct 73 ms 12952 KB Output is correct
50 Correct 75 ms 13080 KB Output is correct
51 Correct 85 ms 13080 KB Output is correct
52 Correct 105 ms 12952 KB Output is correct
53 Correct 79 ms 12952 KB Output is correct
54 Correct 86 ms 13080 KB Output is correct
55 Correct 98 ms 12956 KB Output is correct
56 Correct 67 ms 12948 KB Output is correct
57 Correct 75 ms 13080 KB Output is correct
58 Correct 75 ms 12824 KB Output is correct
59 Correct 82 ms 13080 KB Output is correct
60 Correct 85 ms 13080 KB Output is correct
61 Correct 77 ms 12956 KB Output is correct
62 Correct 103 ms 12956 KB Output is correct
63 Correct 92 ms 12952 KB Output is correct
64 Correct 66 ms 12824 KB Output is correct
65 Correct 85 ms 12956 KB Output is correct
66 Correct 86 ms 12952 KB Output is correct
67 Correct 88 ms 12952 KB Output is correct
68 Correct 88 ms 13080 KB Output is correct
69 Correct 90 ms 12928 KB Output is correct
70 Correct 90 ms 12952 KB Output is correct
71 Correct 394 ms 15900 KB Output is correct
72 Correct 410 ms 16104 KB Output is correct
73 Correct 450 ms 14616 KB Output is correct
74 Correct 762 ms 15128 KB Output is correct
75 Correct 411 ms 17028 KB Output is correct
76 Correct 863 ms 15364 KB Output is correct
77 Correct 708 ms 15128 KB Output is correct
78 Correct 278 ms 18880 KB Output is correct
79 Correct 350 ms 20688 KB Output is correct
80 Correct 398 ms 16140 KB Output is correct
81 Correct 597 ms 15896 KB Output is correct
82 Correct 815 ms 15044 KB Output is correct
83 Correct 435 ms 14232 KB Output is correct
84 Correct 688 ms 15000 KB Output is correct
85 Correct 749 ms 15256 KB Output is correct
86 Correct 248 ms 12824 KB Output is correct
87 Correct 389 ms 15896 KB Output is correct
88 Correct 382 ms 12952 KB Output is correct
89 Correct 568 ms 14620 KB Output is correct
90 Correct 520 ms 15004 KB Output is correct
91 Correct 417 ms 14232 KB Output is correct
92 Correct 838 ms 15288 KB Output is correct
93 Correct 713 ms 15128 KB Output is correct
94 Correct 252 ms 12824 KB Output is correct
95 Correct 637 ms 15004 KB Output is correct
96 Correct 621 ms 15000 KB Output is correct
97 Correct 662 ms 15256 KB Output is correct
98 Correct 613 ms 15128 KB Output is correct
99 Correct 615 ms 15236 KB Output is correct
100 Correct 620 ms 15132 KB Output is correct