답안 #853366

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853366 2023-09-24T08:45:20 Z vjudge1 Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
856 ms 17648 KB
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second 
#define BIT(x,i) (((x)>>(i))&1)
using namespace std;
typedef long long ll;
int dp[1<<20];
int dp1[1<<20];
int l,q;
int sum=0;
string a;
signed main(){
	// freopen("input.inp","r",stdin);
	// freopen("output.out","w",stdout);
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
	cin >> l >> q;
	cin >> a;
	for(int i=0;i<(1<<l);i++){
		int num=a[i]-'0';
		dp[i]=num;
		dp1[i]=num;
	}
	for(int i=0;i<l;i++){
		for(int j=0;j<(1<<l);j++){
			if((1<<i)&j)dp[j]+=dp[j^(1<<i)];
			else dp1[j]+=dp1[j^(1<<i)];
		}
	}
	for(int i=1;i<=q;i++){
		string s;
		cin >> s;
		int mask0=0;
		int num0=0,num1=0,num2=0,mask1=0,mask2=0;
		int sum=0;
		for(int j=0;j<l;j++){
			if(s[l-1-j]=='?'){
				mask2^=(1<<j);
				num2++;
			}
			if(s[l-1-j]=='0'){
				mask0^=(1<<j);
				num0++;
			}
			if(s[l-1-j]=='1'){
				mask1^=(1<<j);
				num1++;
			}
		}
		if(num0<=min(num1,num2)){
			for(int j=mask0;j>=0;j=(j-1)&mask0){
				if(__builtin_popcount(j)%2==0){
					sum+=dp1[mask1^j];
				}
				else{
					sum-=dp1[mask1^j];
				}
				if(j==0)break;
			}

		}
		else if(num1<=min(num0,num2)){
			for(int j=mask1;j>=0;j=(j-1)&mask1){
				if((__builtin_popcount(j)&1)==(__builtin_popcount(mask1)&1)){
					sum+=dp[j^mask2];
				}
				else{
					sum-=dp[j^mask2];
				}
				if(j==0)break;
			}
		}
		else{
			for(int j=mask2;j>=0;j=(j-1)&mask2){	
				sum+=a[j^mask1]-'0';
				if(j==0)break;
			}
		}
		cout << sum << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 174 ms 6416 KB Output is correct
12 Correct 224 ms 5972 KB Output is correct
13 Correct 205 ms 5292 KB Output is correct
14 Correct 238 ms 5344 KB Output is correct
15 Correct 195 ms 6324 KB Output is correct
16 Correct 234 ms 5456 KB Output is correct
17 Correct 244 ms 5460 KB Output is correct
18 Correct 150 ms 7596 KB Output is correct
19 Correct 218 ms 4480 KB Output is correct
20 Correct 199 ms 6068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 174 ms 6416 KB Output is correct
12 Correct 224 ms 5972 KB Output is correct
13 Correct 205 ms 5292 KB Output is correct
14 Correct 238 ms 5344 KB Output is correct
15 Correct 195 ms 6324 KB Output is correct
16 Correct 234 ms 5456 KB Output is correct
17 Correct 244 ms 5460 KB Output is correct
18 Correct 150 ms 7596 KB Output is correct
19 Correct 218 ms 4480 KB Output is correct
20 Correct 199 ms 6068 KB Output is correct
21 Correct 195 ms 6440 KB Output is correct
22 Correct 231 ms 6484 KB Output is correct
23 Correct 255 ms 5584 KB Output is correct
24 Correct 301 ms 5632 KB Output is correct
25 Correct 231 ms 7552 KB Output is correct
26 Correct 338 ms 6024 KB Output is correct
27 Correct 282 ms 5972 KB Output is correct
28 Correct 173 ms 8456 KB Output is correct
29 Correct 179 ms 4436 KB Output is correct
30 Correct 204 ms 6592 KB Output is correct
31 Correct 252 ms 6492 KB Output is correct
32 Correct 370 ms 6512 KB Output is correct
33 Correct 231 ms 5468 KB Output is correct
34 Correct 267 ms 5464 KB Output is correct
35 Correct 272 ms 5812 KB Output is correct
36 Correct 157 ms 4464 KB Output is correct
37 Correct 254 ms 6488 KB Output is correct
38 Correct 195 ms 4432 KB Output is correct
39 Correct 234 ms 5652 KB Output is correct
40 Correct 336 ms 5424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 40 ms 9968 KB Output is correct
12 Correct 39 ms 9980 KB Output is correct
13 Correct 57 ms 9844 KB Output is correct
14 Correct 55 ms 9972 KB Output is correct
15 Correct 44 ms 10048 KB Output is correct
16 Correct 53 ms 10020 KB Output is correct
17 Correct 59 ms 9904 KB Output is correct
18 Correct 36 ms 9968 KB Output is correct
19 Correct 52 ms 9736 KB Output is correct
20 Correct 41 ms 10000 KB Output is correct
21 Correct 54 ms 10044 KB Output is correct
22 Correct 54 ms 9976 KB Output is correct
23 Correct 54 ms 9820 KB Output is correct
24 Correct 67 ms 9836 KB Output is correct
25 Correct 53 ms 9808 KB Output is correct
26 Correct 30 ms 9728 KB Output is correct
27 Correct 38 ms 9820 KB Output is correct
28 Correct 37 ms 9856 KB Output is correct
29 Correct 52 ms 9968 KB Output is correct
30 Correct 41 ms 9920 KB Output is correct
31 Correct 35 ms 9820 KB Output is correct
32 Correct 52 ms 9968 KB Output is correct
33 Correct 64 ms 9972 KB Output is correct
34 Correct 38 ms 9912 KB Output is correct
35 Correct 44 ms 9972 KB Output is correct
36 Correct 47 ms 9944 KB Output is correct
37 Correct 44 ms 9968 KB Output is correct
38 Correct 44 ms 9972 KB Output is correct
39 Correct 61 ms 9968 KB Output is correct
40 Correct 47 ms 10116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 174 ms 6416 KB Output is correct
12 Correct 224 ms 5972 KB Output is correct
13 Correct 205 ms 5292 KB Output is correct
14 Correct 238 ms 5344 KB Output is correct
15 Correct 195 ms 6324 KB Output is correct
16 Correct 234 ms 5456 KB Output is correct
17 Correct 244 ms 5460 KB Output is correct
18 Correct 150 ms 7596 KB Output is correct
19 Correct 218 ms 4480 KB Output is correct
20 Correct 199 ms 6068 KB Output is correct
21 Correct 195 ms 6440 KB Output is correct
22 Correct 231 ms 6484 KB Output is correct
23 Correct 255 ms 5584 KB Output is correct
24 Correct 301 ms 5632 KB Output is correct
25 Correct 231 ms 7552 KB Output is correct
26 Correct 338 ms 6024 KB Output is correct
27 Correct 282 ms 5972 KB Output is correct
28 Correct 173 ms 8456 KB Output is correct
29 Correct 179 ms 4436 KB Output is correct
30 Correct 204 ms 6592 KB Output is correct
31 Correct 252 ms 6492 KB Output is correct
32 Correct 370 ms 6512 KB Output is correct
33 Correct 231 ms 5468 KB Output is correct
34 Correct 267 ms 5464 KB Output is correct
35 Correct 272 ms 5812 KB Output is correct
36 Correct 157 ms 4464 KB Output is correct
37 Correct 254 ms 6488 KB Output is correct
38 Correct 195 ms 4432 KB Output is correct
39 Correct 234 ms 5652 KB Output is correct
40 Correct 336 ms 5424 KB Output is correct
41 Correct 40 ms 9968 KB Output is correct
42 Correct 39 ms 9980 KB Output is correct
43 Correct 57 ms 9844 KB Output is correct
44 Correct 55 ms 9972 KB Output is correct
45 Correct 44 ms 10048 KB Output is correct
46 Correct 53 ms 10020 KB Output is correct
47 Correct 59 ms 9904 KB Output is correct
48 Correct 36 ms 9968 KB Output is correct
49 Correct 52 ms 9736 KB Output is correct
50 Correct 41 ms 10000 KB Output is correct
51 Correct 54 ms 10044 KB Output is correct
52 Correct 54 ms 9976 KB Output is correct
53 Correct 54 ms 9820 KB Output is correct
54 Correct 67 ms 9836 KB Output is correct
55 Correct 53 ms 9808 KB Output is correct
56 Correct 30 ms 9728 KB Output is correct
57 Correct 38 ms 9820 KB Output is correct
58 Correct 37 ms 9856 KB Output is correct
59 Correct 52 ms 9968 KB Output is correct
60 Correct 41 ms 9920 KB Output is correct
61 Correct 35 ms 9820 KB Output is correct
62 Correct 52 ms 9968 KB Output is correct
63 Correct 64 ms 9972 KB Output is correct
64 Correct 38 ms 9912 KB Output is correct
65 Correct 44 ms 9972 KB Output is correct
66 Correct 47 ms 9944 KB Output is correct
67 Correct 44 ms 9968 KB Output is correct
68 Correct 44 ms 9972 KB Output is correct
69 Correct 61 ms 9968 KB Output is correct
70 Correct 47 ms 10116 KB Output is correct
71 Correct 334 ms 14836 KB Output is correct
72 Correct 316 ms 14840 KB Output is correct
73 Correct 368 ms 13688 KB Output is correct
74 Correct 568 ms 13808 KB Output is correct
75 Correct 341 ms 15600 KB Output is correct
76 Correct 856 ms 14112 KB Output is correct
77 Correct 753 ms 13836 KB Output is correct
78 Correct 305 ms 17648 KB Output is correct
79 Correct 308 ms 11592 KB Output is correct
80 Correct 297 ms 14836 KB Output is correct
81 Correct 446 ms 14684 KB Output is correct
82 Correct 579 ms 13716 KB Output is correct
83 Correct 310 ms 13000 KB Output is correct
84 Correct 462 ms 13812 KB Output is correct
85 Correct 450 ms 14088 KB Output is correct
86 Correct 200 ms 11616 KB Output is correct
87 Correct 284 ms 14832 KB Output is correct
88 Correct 276 ms 11576 KB Output is correct
89 Correct 352 ms 13396 KB Output is correct
90 Correct 394 ms 13684 KB Output is correct
91 Correct 295 ms 12972 KB Output is correct
92 Correct 496 ms 14120 KB Output is correct
93 Correct 468 ms 14140 KB Output is correct
94 Correct 203 ms 11804 KB Output is correct
95 Correct 383 ms 13692 KB Output is correct
96 Correct 445 ms 13968 KB Output is correct
97 Correct 451 ms 13752 KB Output is correct
98 Correct 387 ms 13820 KB Output is correct
99 Correct 396 ms 13908 KB Output is correct
100 Correct 442 ms 14296 KB Output is correct