답안 #234944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234944 2020-05-26T11:53:47 Z amoo_safar Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
622 ms 19124 KB
#include <bits/stdc++.h>

#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#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;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 223 ms 5880 KB Output is correct
12 Correct 250 ms 5736 KB Output is correct
13 Correct 254 ms 4984 KB Output is correct
14 Correct 251 ms 4984 KB Output is correct
15 Correct 242 ms 6012 KB Output is correct
16 Correct 270 ms 5240 KB Output is correct
17 Correct 279 ms 5112 KB Output is correct
18 Correct 186 ms 6904 KB Output is correct
19 Correct 227 ms 3960 KB Output is correct
20 Correct 236 ms 5496 KB Output is correct
# 결과 실행 시간 메모리 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 223 ms 5880 KB Output is correct
12 Correct 250 ms 5736 KB Output is correct
13 Correct 254 ms 4984 KB Output is correct
14 Correct 251 ms 4984 KB Output is correct
15 Correct 242 ms 6012 KB Output is correct
16 Correct 270 ms 5240 KB Output is correct
17 Correct 279 ms 5112 KB Output is correct
18 Correct 186 ms 6904 KB Output is correct
19 Correct 227 ms 3960 KB Output is correct
20 Correct 236 ms 5496 KB Output is correct
21 Correct 244 ms 6008 KB Output is correct
22 Correct 266 ms 6280 KB Output is correct
23 Correct 289 ms 5240 KB Output is correct
24 Correct 309 ms 5112 KB Output is correct
25 Correct 261 ms 7288 KB Output is correct
26 Correct 310 ms 5620 KB Output is correct
27 Correct 318 ms 5516 KB Output is correct
28 Correct 213 ms 8056 KB Output is correct
29 Correct 241 ms 4088 KB Output is correct
30 Correct 262 ms 6216 KB Output is correct
31 Correct 296 ms 5964 KB Output is correct
32 Correct 306 ms 6136 KB Output is correct
33 Correct 284 ms 4984 KB Output is correct
34 Correct 322 ms 5088 KB Output is correct
35 Correct 315 ms 5536 KB Output is correct
36 Correct 173 ms 3960 KB Output is correct
37 Correct 247 ms 6008 KB Output is correct
38 Correct 257 ms 4040 KB Output is correct
39 Correct 303 ms 5240 KB Output is correct
40 Correct 305 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 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 60 ms 12056 KB Output is correct
12 Correct 64 ms 12056 KB Output is correct
13 Correct 60 ms 11928 KB Output is correct
14 Correct 72 ms 11928 KB Output is correct
15 Correct 65 ms 12184 KB Output is correct
16 Correct 72 ms 12056 KB Output is correct
17 Correct 75 ms 11928 KB Output is correct
18 Correct 58 ms 12184 KB Output is correct
19 Correct 59 ms 11928 KB Output is correct
20 Correct 61 ms 12056 KB Output is correct
21 Correct 67 ms 12056 KB Output is correct
22 Correct 74 ms 11956 KB Output is correct
23 Correct 63 ms 11928 KB Output is correct
24 Correct 68 ms 12056 KB Output is correct
25 Correct 69 ms 12056 KB Output is correct
26 Correct 58 ms 11928 KB Output is correct
27 Correct 59 ms 12056 KB Output is correct
28 Correct 61 ms 11928 KB Output is correct
29 Correct 67 ms 11928 KB Output is correct
30 Correct 66 ms 11928 KB Output is correct
31 Correct 60 ms 11932 KB Output is correct
32 Correct 78 ms 12056 KB Output is correct
33 Correct 133 ms 12056 KB Output is correct
34 Correct 63 ms 11928 KB Output is correct
35 Correct 68 ms 11928 KB Output is correct
36 Correct 80 ms 11928 KB Output is correct
37 Correct 75 ms 12052 KB Output is correct
38 Correct 73 ms 11928 KB Output is correct
39 Correct 67 ms 11928 KB Output is correct
40 Correct 72 ms 11932 KB Output is correct
# 결과 실행 시간 메모리 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 223 ms 5880 KB Output is correct
12 Correct 250 ms 5736 KB Output is correct
13 Correct 254 ms 4984 KB Output is correct
14 Correct 251 ms 4984 KB Output is correct
15 Correct 242 ms 6012 KB Output is correct
16 Correct 270 ms 5240 KB Output is correct
17 Correct 279 ms 5112 KB Output is correct
18 Correct 186 ms 6904 KB Output is correct
19 Correct 227 ms 3960 KB Output is correct
20 Correct 236 ms 5496 KB Output is correct
21 Correct 244 ms 6008 KB Output is correct
22 Correct 266 ms 6280 KB Output is correct
23 Correct 289 ms 5240 KB Output is correct
24 Correct 309 ms 5112 KB Output is correct
25 Correct 261 ms 7288 KB Output is correct
26 Correct 310 ms 5620 KB Output is correct
27 Correct 318 ms 5516 KB Output is correct
28 Correct 213 ms 8056 KB Output is correct
29 Correct 241 ms 4088 KB Output is correct
30 Correct 262 ms 6216 KB Output is correct
31 Correct 296 ms 5964 KB Output is correct
32 Correct 306 ms 6136 KB Output is correct
33 Correct 284 ms 4984 KB Output is correct
34 Correct 322 ms 5088 KB Output is correct
35 Correct 315 ms 5536 KB Output is correct
36 Correct 173 ms 3960 KB Output is correct
37 Correct 247 ms 6008 KB Output is correct
38 Correct 257 ms 4040 KB Output is correct
39 Correct 303 ms 5240 KB Output is correct
40 Correct 305 ms 4984 KB Output is correct
41 Correct 60 ms 12056 KB Output is correct
42 Correct 64 ms 12056 KB Output is correct
43 Correct 60 ms 11928 KB Output is correct
44 Correct 72 ms 11928 KB Output is correct
45 Correct 65 ms 12184 KB Output is correct
46 Correct 72 ms 12056 KB Output is correct
47 Correct 75 ms 11928 KB Output is correct
48 Correct 58 ms 12184 KB Output is correct
49 Correct 59 ms 11928 KB Output is correct
50 Correct 61 ms 12056 KB Output is correct
51 Correct 67 ms 12056 KB Output is correct
52 Correct 74 ms 11956 KB Output is correct
53 Correct 63 ms 11928 KB Output is correct
54 Correct 68 ms 12056 KB Output is correct
55 Correct 69 ms 12056 KB Output is correct
56 Correct 58 ms 11928 KB Output is correct
57 Correct 59 ms 12056 KB Output is correct
58 Correct 61 ms 11928 KB Output is correct
59 Correct 67 ms 11928 KB Output is correct
60 Correct 66 ms 11928 KB Output is correct
61 Correct 60 ms 11932 KB Output is correct
62 Correct 78 ms 12056 KB Output is correct
63 Correct 133 ms 12056 KB Output is correct
64 Correct 63 ms 11928 KB Output is correct
65 Correct 68 ms 11928 KB Output is correct
66 Correct 80 ms 11928 KB Output is correct
67 Correct 75 ms 12052 KB Output is correct
68 Correct 73 ms 11928 KB Output is correct
69 Correct 67 ms 11928 KB Output is correct
70 Correct 72 ms 11932 KB Output is correct
71 Correct 373 ms 16024 KB Output is correct
72 Correct 379 ms 16152 KB Output is correct
73 Correct 427 ms 14616 KB Output is correct
74 Correct 528 ms 15044 KB Output is correct
75 Correct 378 ms 17188 KB Output is correct
76 Correct 622 ms 15512 KB Output is correct
77 Correct 586 ms 15256 KB Output is correct
78 Correct 249 ms 19124 KB Output is correct
79 Correct 353 ms 15040 KB Output is correct
80 Correct 397 ms 16104 KB Output is correct
81 Correct 488 ms 16028 KB Output is correct
82 Correct 537 ms 15004 KB Output is correct
83 Correct 390 ms 14232 KB Output is correct
84 Correct 544 ms 15004 KB Output is correct
85 Correct 590 ms 15248 KB Output is correct
86 Correct 231 ms 13060 KB Output is correct
87 Correct 382 ms 15944 KB Output is correct
88 Correct 355 ms 12952 KB Output is correct
89 Correct 458 ms 14524 KB Output is correct
90 Correct 482 ms 14976 KB Output is correct
91 Correct 364 ms 14104 KB Output is correct
92 Correct 616 ms 15256 KB Output is correct
93 Correct 591 ms 15128 KB Output is correct
94 Correct 239 ms 12824 KB Output is correct
95 Correct 514 ms 15128 KB Output is correct
96 Correct 526 ms 15344 KB Output is correct
97 Correct 490 ms 15000 KB Output is correct
98 Correct 533 ms 14928 KB Output is correct
99 Correct 504 ms 15000 KB Output is correct
100 Correct 499 ms 15000 KB Output is correct