Submission #234937

# Submission time Handle Problem Language Result Execution time Memory
234937 2020-05-26T11:30:18 Z amoo_safar Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 39448 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;
	cin >> 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;
		for(int i = 0; i < L; i++){
			if(s[i] == '1') mk1 |= (1 << (L - 1 - i));
			if(s[i] == '0') mk0 |= (1 << (L - 1 - i));	
		}
		if(__builtin_popcount(mk0) < __builtin_popcount(mk1)){
			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 5 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 5 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 230 ms 5496 KB Output is correct
12 Correct 231 ms 5240 KB Output is correct
13 Correct 262 ms 4472 KB Output is correct
14 Correct 260 ms 4600 KB Output is correct
15 Correct 234 ms 5636 KB Output is correct
16 Correct 271 ms 4728 KB Output is correct
17 Correct 282 ms 4748 KB Output is correct
18 Correct 193 ms 6520 KB Output is correct
19 Correct 346 ms 3576 KB Output is correct
20 Correct 233 ms 5240 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 5 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 230 ms 5496 KB Output is correct
12 Correct 231 ms 5240 KB Output is correct
13 Correct 262 ms 4472 KB Output is correct
14 Correct 260 ms 4600 KB Output is correct
15 Correct 234 ms 5636 KB Output is correct
16 Correct 271 ms 4728 KB Output is correct
17 Correct 282 ms 4748 KB Output is correct
18 Correct 193 ms 6520 KB Output is correct
19 Correct 346 ms 3576 KB Output is correct
20 Correct 233 ms 5240 KB Output is correct
21 Correct 247 ms 5624 KB Output is correct
22 Correct 262 ms 5808 KB Output is correct
23 Correct 331 ms 4600 KB Output is correct
24 Correct 334 ms 4472 KB Output is correct
25 Correct 260 ms 6640 KB Output is correct
26 Correct 335 ms 4984 KB Output is correct
27 Correct 335 ms 4912 KB Output is correct
28 Correct 192 ms 7288 KB Output is correct
29 Correct 499 ms 3320 KB Output is correct
30 Correct 258 ms 5496 KB Output is correct
31 Correct 298 ms 5240 KB Output is correct
32 Correct 344 ms 5240 KB Output is correct
33 Correct 291 ms 4088 KB Output is correct
34 Correct 324 ms 4216 KB Output is correct
35 Correct 340 ms 4600 KB Output is correct
36 Correct 173 ms 3064 KB Output is correct
37 Correct 242 ms 5112 KB Output is correct
38 Correct 403 ms 3064 KB Output is correct
39 Correct 344 ms 4348 KB Output is correct
40 Correct 340 ms 3960 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 5 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 68 ms 10392 KB Output is correct
12 Correct 69 ms 10392 KB Output is correct
13 Correct 84 ms 10264 KB Output is correct
14 Correct 85 ms 10264 KB Output is correct
15 Correct 71 ms 10392 KB Output is correct
16 Correct 97 ms 10260 KB Output is correct
17 Correct 103 ms 10340 KB Output is correct
18 Correct 62 ms 10548 KB Output is correct
19 Correct 288 ms 10268 KB Output is correct
20 Correct 69 ms 10392 KB Output is correct
21 Correct 81 ms 10396 KB Output is correct
22 Correct 88 ms 10264 KB Output is correct
23 Correct 75 ms 10264 KB Output is correct
24 Correct 107 ms 10264 KB Output is correct
25 Correct 99 ms 10264 KB Output is correct
26 Correct 62 ms 10264 KB Output is correct
27 Correct 68 ms 10392 KB Output is correct
28 Correct 165 ms 10148 KB Output is correct
29 Correct 87 ms 10264 KB Output is correct
30 Correct 104 ms 10268 KB Output is correct
31 Correct 68 ms 10140 KB Output is correct
32 Correct 99 ms 10264 KB Output is correct
33 Correct 109 ms 10136 KB Output is correct
34 Correct 61 ms 11032 KB Output is correct
35 Correct 99 ms 11800 KB Output is correct
36 Correct 106 ms 12056 KB Output is correct
37 Correct 105 ms 11928 KB Output is correct
38 Correct 104 ms 11924 KB Output is correct
39 Correct 111 ms 11928 KB Output is correct
40 Correct 106 ms 12056 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 5 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 230 ms 5496 KB Output is correct
12 Correct 231 ms 5240 KB Output is correct
13 Correct 262 ms 4472 KB Output is correct
14 Correct 260 ms 4600 KB Output is correct
15 Correct 234 ms 5636 KB Output is correct
16 Correct 271 ms 4728 KB Output is correct
17 Correct 282 ms 4748 KB Output is correct
18 Correct 193 ms 6520 KB Output is correct
19 Correct 346 ms 3576 KB Output is correct
20 Correct 233 ms 5240 KB Output is correct
21 Correct 247 ms 5624 KB Output is correct
22 Correct 262 ms 5808 KB Output is correct
23 Correct 331 ms 4600 KB Output is correct
24 Correct 334 ms 4472 KB Output is correct
25 Correct 260 ms 6640 KB Output is correct
26 Correct 335 ms 4984 KB Output is correct
27 Correct 335 ms 4912 KB Output is correct
28 Correct 192 ms 7288 KB Output is correct
29 Correct 499 ms 3320 KB Output is correct
30 Correct 258 ms 5496 KB Output is correct
31 Correct 298 ms 5240 KB Output is correct
32 Correct 344 ms 5240 KB Output is correct
33 Correct 291 ms 4088 KB Output is correct
34 Correct 324 ms 4216 KB Output is correct
35 Correct 340 ms 4600 KB Output is correct
36 Correct 173 ms 3064 KB Output is correct
37 Correct 242 ms 5112 KB Output is correct
38 Correct 403 ms 3064 KB Output is correct
39 Correct 344 ms 4348 KB Output is correct
40 Correct 340 ms 3960 KB Output is correct
41 Correct 68 ms 10392 KB Output is correct
42 Correct 69 ms 10392 KB Output is correct
43 Correct 84 ms 10264 KB Output is correct
44 Correct 85 ms 10264 KB Output is correct
45 Correct 71 ms 10392 KB Output is correct
46 Correct 97 ms 10260 KB Output is correct
47 Correct 103 ms 10340 KB Output is correct
48 Correct 62 ms 10548 KB Output is correct
49 Correct 288 ms 10268 KB Output is correct
50 Correct 69 ms 10392 KB Output is correct
51 Correct 81 ms 10396 KB Output is correct
52 Correct 88 ms 10264 KB Output is correct
53 Correct 75 ms 10264 KB Output is correct
54 Correct 107 ms 10264 KB Output is correct
55 Correct 99 ms 10264 KB Output is correct
56 Correct 62 ms 10264 KB Output is correct
57 Correct 68 ms 10392 KB Output is correct
58 Correct 165 ms 10148 KB Output is correct
59 Correct 87 ms 10264 KB Output is correct
60 Correct 104 ms 10268 KB Output is correct
61 Correct 68 ms 10140 KB Output is correct
62 Correct 99 ms 10264 KB Output is correct
63 Correct 109 ms 10136 KB Output is correct
64 Correct 61 ms 11032 KB Output is correct
65 Correct 99 ms 11800 KB Output is correct
66 Correct 106 ms 12056 KB Output is correct
67 Correct 105 ms 11928 KB Output is correct
68 Correct 104 ms 11924 KB Output is correct
69 Correct 111 ms 11928 KB Output is correct
70 Correct 106 ms 12056 KB Output is correct
71 Correct 396 ms 36424 KB Output is correct
72 Correct 407 ms 36504 KB Output is correct
73 Correct 654 ms 34968 KB Output is correct
74 Correct 766 ms 35476 KB Output is correct
75 Correct 406 ms 37476 KB Output is correct
76 Correct 975 ms 35672 KB Output is correct
77 Correct 1120 ms 35540 KB Output is correct
78 Correct 287 ms 39448 KB Output is correct
79 Execution timed out 2089 ms 21144 KB Time limit exceeded
80 Halted 0 ms 0 KB -