답안 #860635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860635 2023-10-13T15:03:32 Z phoenix0423 Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
254 ms 13908 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
const int maxn = 1e5 + 5;
const int sqrtn = 500;
int super[maxn], sub[maxn];
//sos dp + sqrt-sort technique(pigeonhole principle)

int main(void){
	fastio;
	int l, q;
	cin>>l>>q;
	string s;
	cin>>s;
	for(int i = 0; i < (1 << l); i++) sub[i] = super[i] = s[i] - '0';
	for(int i = 0; i < l; i++){
		for(int mask = 0; mask < (1 << l); mask++){
			if(mask & (1 << i)) sub[mask] += sub[mask ^ (1 << i)];
			else super[mask] += super[mask ^ (1 << i)];
		}
	}
	while(q--){
		string t;
		cin>>t;
		int cnt0 = 0, cnt1 = 0, cnt2 = 0;
		int a = 0, b = 0, c = 0; //a = 0, b = 1, c = 2
		for(int i = 0; i < l; i++){
			char x = t[i];
			if(x == '0') cnt0++, a |= (1 << (l - i - 1));
			else if(x == '1') cnt1++, b |= (1 << (l - i - 1));
			else cnt2++, c |= (1 << (l - i - 1));
		}
		int ans = 0;
		if(cnt2 <= cnt0 && cnt2 <= cnt1){
			for(int mask = c; mask > 0; mask = (mask - 1) & c){
				ans += s[mask | b] - '0';
			}
			ans += s[b] - '0';
		}
		else if(cnt0 <= cnt1){
			for(int mask = a; mask > 0; mask = (mask - 1) & a){
				ans += (1 - 2 * (__builtin_popcount(mask) & 1)) * super[mask | b];
			}
			ans += super[b];
		}
		else{
			for(int mask = b; mask > 0; mask = (mask - 1) & b){
				ans += (1 - 2 * (__builtin_popcount(mask) & 1)) * sub[c | (b ^ mask)];
			}
			ans += sub[c | b];
		}
		cout<<ans<<"\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 158 ms 4432 KB Output is correct
12 Correct 169 ms 10064 KB Output is correct
13 Correct 200 ms 9316 KB Output is correct
14 Correct 189 ms 9564 KB Output is correct
15 Correct 182 ms 10576 KB Output is correct
16 Correct 208 ms 9888 KB Output is correct
17 Correct 206 ms 9704 KB Output is correct
18 Correct 141 ms 11592 KB Output is correct
19 Correct 157 ms 8484 KB Output is correct
20 Correct 174 ms 10444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 158 ms 4432 KB Output is correct
12 Correct 169 ms 10064 KB Output is correct
13 Correct 200 ms 9316 KB Output is correct
14 Correct 189 ms 9564 KB Output is correct
15 Correct 182 ms 10576 KB Output is correct
16 Correct 208 ms 9888 KB Output is correct
17 Correct 206 ms 9704 KB Output is correct
18 Correct 141 ms 11592 KB Output is correct
19 Correct 157 ms 8484 KB Output is correct
20 Correct 174 ms 10444 KB Output is correct
21 Correct 187 ms 11828 KB Output is correct
22 Correct 195 ms 11976 KB Output is correct
23 Correct 238 ms 11004 KB Output is correct
24 Correct 223 ms 10836 KB Output is correct
25 Correct 209 ms 12892 KB Output is correct
26 Correct 254 ms 11432 KB Output is correct
27 Correct 248 ms 11348 KB Output is correct
28 Correct 151 ms 13908 KB Output is correct
29 Correct 209 ms 9808 KB Output is correct
30 Correct 193 ms 12112 KB Output is correct
31 Correct 228 ms 11756 KB Output is correct
32 Correct 253 ms 11852 KB Output is correct
33 Correct 202 ms 10832 KB Output is correct
34 Correct 233 ms 10940 KB Output is correct
35 Correct 252 ms 11516 KB Output is correct
36 Correct 146 ms 9808 KB Output is correct
37 Correct 181 ms 11860 KB Output is correct
38 Correct 197 ms 9900 KB Output is correct
39 Correct 221 ms 11088 KB Output is correct
40 Correct 217 ms 10876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Runtime error 4 ms 4352 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 158 ms 4432 KB Output is correct
12 Correct 169 ms 10064 KB Output is correct
13 Correct 200 ms 9316 KB Output is correct
14 Correct 189 ms 9564 KB Output is correct
15 Correct 182 ms 10576 KB Output is correct
16 Correct 208 ms 9888 KB Output is correct
17 Correct 206 ms 9704 KB Output is correct
18 Correct 141 ms 11592 KB Output is correct
19 Correct 157 ms 8484 KB Output is correct
20 Correct 174 ms 10444 KB Output is correct
21 Correct 187 ms 11828 KB Output is correct
22 Correct 195 ms 11976 KB Output is correct
23 Correct 238 ms 11004 KB Output is correct
24 Correct 223 ms 10836 KB Output is correct
25 Correct 209 ms 12892 KB Output is correct
26 Correct 254 ms 11432 KB Output is correct
27 Correct 248 ms 11348 KB Output is correct
28 Correct 151 ms 13908 KB Output is correct
29 Correct 209 ms 9808 KB Output is correct
30 Correct 193 ms 12112 KB Output is correct
31 Correct 228 ms 11756 KB Output is correct
32 Correct 253 ms 11852 KB Output is correct
33 Correct 202 ms 10832 KB Output is correct
34 Correct 233 ms 10940 KB Output is correct
35 Correct 252 ms 11516 KB Output is correct
36 Correct 146 ms 9808 KB Output is correct
37 Correct 181 ms 11860 KB Output is correct
38 Correct 197 ms 9900 KB Output is correct
39 Correct 221 ms 11088 KB Output is correct
40 Correct 217 ms 10876 KB Output is correct
41 Runtime error 4 ms 4352 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -