답안 #535650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535650 2022-03-10T19:13:32 Z Arnch Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
593 ms 10756 KB
// oooo
/*
 har chi delet mikhad bebar ~
 gitar o ba khodet nabar! ~
 ;Amoo_Hasan;
*/

#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")

using namespace std;

typedef long long ll;
typedef long double ld;

#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define endl '\n'

constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, pr = 1000696969;

int a[N], fd[N], fu[N], fu2[N];

int main() {
    ios :: sync_with_stdio(0), cin.tie(0);

	int l, q; cin >>l >>q;
	string s; cin >>s;
	for(int i = 0; i < Sz(s); i++) {
		a[i] = s[i] - '0';
	}

	int to = (1 << l) - 1;
	for(int i = 0; i < (1 << l); i++) {
		fd[i] = a[i], fu2[i ^ to] = a[i];
	}
	for(int i = 0; i < l; i++) {
		for(int mask = 0; mask < (1 << l); mask++) {
			if((mask >> i) & 1) {
				fd[mask] += fd[mask ^ (1 << i)];
				fu2[mask] += fu2[mask ^ (1 << i)];
			}
		}
	}

	for(int mask = 0; mask < (1 << l); mask++) {
		fu[mask] = fu2[mask ^ to];
	}


	while(q--) {
		cin >>s;
		int cnt0 = 0, cnt1 = 0, cnt = 0;
		for(int i = 0; i < Sz(s); i++) {
			cnt0 += (s[i] == '0');
			cnt1 += (s[i] == '1');
			cnt += (s[i] == '?');
		}
		int mask = 0, mask2 = 0;

		if(cnt <= 6) {
			for(int i = 0; i < Sz(s); i++) {
				if(s[i] == '?') mask2 += (1 << (Sz(s) - i - 1));
				if(s[i] == '1') mask += (1 << (Sz(s) - i - 1));
			}
			int ans = a[mask];
			for(int i = mask2; i > 0; i = (i - 1) & mask2) {
				ans += a[i + mask];
			}
			cout<<ans <<endl;
			continue;
		}

		if(cnt1 <= 6) {
			for(int i = 0; i < Sz(s); i++) {
				if(s[i] == '1') mask2 += (1 << (Sz(s) - i - 1));
				if(s[i] == '?') mask += (1 << (Sz(s) - i - 1));
			}
			int cnte = __builtin_popcount(mask2) & 1, ans = 0;
			for(int i = mask2; i > 0; i = (i - 1) & mask2) {
				if((__builtin_popcount(i) & 1) == cnte) ans += fd[i + mask];
				else ans -= fd[i + mask];
			}
			if(cnte == 0) ans += fd[mask];
			else ans -= fd[mask];
			cout<<ans <<endl;
			continue;
		}

		for(int i = 0; i < Sz(s); i++) {
			if(s[i] == '0') mask2 += (1 << (Sz(s) - i - 1));
			if(s[i] == '1') mask += (1 << (Sz(s) - i - 1));
		}
		int cnte = 0, ans = 0;
		for(int i = mask2; i > 0; i = (i - 1) & mask2) {
			if((__builtin_popcount(i) & 1) == cnte) ans += fu[i + mask];
			else ans -= fu[i + mask];
		}
		ans += fu[mask];
		cout<<ans <<endl;
	}

	

	
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 230 ms 4340 KB Output is correct
12 Correct 242 ms 3920 KB Output is correct
13 Correct 188 ms 3228 KB Output is correct
14 Correct 189 ms 3248 KB Output is correct
15 Correct 275 ms 4296 KB Output is correct
16 Correct 225 ms 3468 KB Output is correct
17 Correct 202 ms 3420 KB Output is correct
18 Correct 176 ms 5268 KB Output is correct
19 Correct 155 ms 2272 KB Output is correct
20 Correct 305 ms 4020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 230 ms 4340 KB Output is correct
12 Correct 242 ms 3920 KB Output is correct
13 Correct 188 ms 3228 KB Output is correct
14 Correct 189 ms 3248 KB Output is correct
15 Correct 275 ms 4296 KB Output is correct
16 Correct 225 ms 3468 KB Output is correct
17 Correct 202 ms 3420 KB Output is correct
18 Correct 176 ms 5268 KB Output is correct
19 Correct 155 ms 2272 KB Output is correct
20 Correct 305 ms 4020 KB Output is correct
21 Correct 593 ms 4604 KB Output is correct
22 Correct 221 ms 4584 KB Output is correct
23 Correct 247 ms 3572 KB Output is correct
24 Correct 218 ms 3408 KB Output is correct
25 Correct 263 ms 5484 KB Output is correct
26 Correct 256 ms 3900 KB Output is correct
27 Correct 240 ms 4008 KB Output is correct
28 Correct 195 ms 6476 KB Output is correct
29 Correct 208 ms 2396 KB Output is correct
30 Correct 326 ms 4696 KB Output is correct
31 Correct 282 ms 4500 KB Output is correct
32 Correct 241 ms 4408 KB Output is correct
33 Correct 228 ms 3328 KB Output is correct
34 Correct 212 ms 3452 KB Output is correct
35 Correct 252 ms 3928 KB Output is correct
36 Correct 158 ms 2492 KB Output is correct
37 Correct 294 ms 4440 KB Output is correct
38 Correct 157 ms 2508 KB Output is correct
39 Correct 228 ms 3656 KB Output is correct
40 Correct 228 ms 3468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Runtime error 10 ms 10756 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 230 ms 4340 KB Output is correct
12 Correct 242 ms 3920 KB Output is correct
13 Correct 188 ms 3228 KB Output is correct
14 Correct 189 ms 3248 KB Output is correct
15 Correct 275 ms 4296 KB Output is correct
16 Correct 225 ms 3468 KB Output is correct
17 Correct 202 ms 3420 KB Output is correct
18 Correct 176 ms 5268 KB Output is correct
19 Correct 155 ms 2272 KB Output is correct
20 Correct 305 ms 4020 KB Output is correct
21 Correct 593 ms 4604 KB Output is correct
22 Correct 221 ms 4584 KB Output is correct
23 Correct 247 ms 3572 KB Output is correct
24 Correct 218 ms 3408 KB Output is correct
25 Correct 263 ms 5484 KB Output is correct
26 Correct 256 ms 3900 KB Output is correct
27 Correct 240 ms 4008 KB Output is correct
28 Correct 195 ms 6476 KB Output is correct
29 Correct 208 ms 2396 KB Output is correct
30 Correct 326 ms 4696 KB Output is correct
31 Correct 282 ms 4500 KB Output is correct
32 Correct 241 ms 4408 KB Output is correct
33 Correct 228 ms 3328 KB Output is correct
34 Correct 212 ms 3452 KB Output is correct
35 Correct 252 ms 3928 KB Output is correct
36 Correct 158 ms 2492 KB Output is correct
37 Correct 294 ms 4440 KB Output is correct
38 Correct 157 ms 2508 KB Output is correct
39 Correct 228 ms 3656 KB Output is correct
40 Correct 228 ms 3468 KB Output is correct
41 Runtime error 10 ms 10756 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -