Submission #535649

# Submission time Handle Problem Language Result Execution time Memory
535649 2022-03-10T19:08:33 Z Arnch Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
309 ms 10744 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 cnt = __builtin_popcount(mask2) & 1, ans = 0;
			for(int i = mask2; i > 0; i = (i - 1) & mask2) {
				if((__builtin_popcount(i) & 1) == cnt) ans += fd[i + mask];
				else ans -= fd[i + mask];
			}
			if(cnt == 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;
}


# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 247 ms 4428 KB Output is correct
12 Correct 246 ms 4000 KB Output is correct
13 Correct 189 ms 3240 KB Output is correct
14 Correct 197 ms 3340 KB Output is correct
15 Correct 248 ms 4360 KB Output is correct
16 Correct 213 ms 3532 KB Output is correct
17 Correct 213 ms 3436 KB Output is correct
18 Correct 166 ms 5276 KB Output is correct
19 Correct 172 ms 2244 KB Output is correct
20 Correct 220 ms 3944 KB Output is correct
# Verdict Execution time Memory 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 247 ms 4428 KB Output is correct
12 Correct 246 ms 4000 KB Output is correct
13 Correct 189 ms 3240 KB Output is correct
14 Correct 197 ms 3340 KB Output is correct
15 Correct 248 ms 4360 KB Output is correct
16 Correct 213 ms 3532 KB Output is correct
17 Correct 213 ms 3436 KB Output is correct
18 Correct 166 ms 5276 KB Output is correct
19 Correct 172 ms 2244 KB Output is correct
20 Correct 220 ms 3944 KB Output is correct
21 Correct 309 ms 4472 KB Output is correct
22 Correct 236 ms 4648 KB Output is correct
23 Correct 229 ms 3596 KB Output is correct
24 Correct 233 ms 3568 KB Output is correct
25 Correct 228 ms 5500 KB Output is correct
26 Correct 231 ms 3968 KB Output is correct
27 Correct 238 ms 3912 KB Output is correct
28 Correct 196 ms 6476 KB Output is correct
29 Correct 173 ms 2380 KB Output is correct
30 Correct 290 ms 4556 KB Output is correct
31 Correct 298 ms 4388 KB Output is correct
32 Correct 260 ms 4548 KB Output is correct
33 Correct 199 ms 3292 KB Output is correct
34 Correct 218 ms 3412 KB Output is correct
35 Correct 228 ms 3872 KB Output is correct
36 Correct 174 ms 2396 KB Output is correct
37 Correct 288 ms 4412 KB Output is correct
38 Correct 172 ms 2528 KB Output is correct
39 Correct 236 ms 3608 KB Output is correct
40 Correct 218 ms 3504 KB Output is correct
# Verdict Execution time Memory 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 12 ms 10744 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 247 ms 4428 KB Output is correct
12 Correct 246 ms 4000 KB Output is correct
13 Correct 189 ms 3240 KB Output is correct
14 Correct 197 ms 3340 KB Output is correct
15 Correct 248 ms 4360 KB Output is correct
16 Correct 213 ms 3532 KB Output is correct
17 Correct 213 ms 3436 KB Output is correct
18 Correct 166 ms 5276 KB Output is correct
19 Correct 172 ms 2244 KB Output is correct
20 Correct 220 ms 3944 KB Output is correct
21 Correct 309 ms 4472 KB Output is correct
22 Correct 236 ms 4648 KB Output is correct
23 Correct 229 ms 3596 KB Output is correct
24 Correct 233 ms 3568 KB Output is correct
25 Correct 228 ms 5500 KB Output is correct
26 Correct 231 ms 3968 KB Output is correct
27 Correct 238 ms 3912 KB Output is correct
28 Correct 196 ms 6476 KB Output is correct
29 Correct 173 ms 2380 KB Output is correct
30 Correct 290 ms 4556 KB Output is correct
31 Correct 298 ms 4388 KB Output is correct
32 Correct 260 ms 4548 KB Output is correct
33 Correct 199 ms 3292 KB Output is correct
34 Correct 218 ms 3412 KB Output is correct
35 Correct 228 ms 3872 KB Output is correct
36 Correct 174 ms 2396 KB Output is correct
37 Correct 288 ms 4412 KB Output is correct
38 Correct 172 ms 2528 KB Output is correct
39 Correct 236 ms 3608 KB Output is correct
40 Correct 218 ms 3504 KB Output is correct
41 Runtime error 12 ms 10744 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -