Submission #763105

# Submission time Handle Problem Language Result Execution time Memory
763105 2023-06-22T03:44:38 Z sentheta Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
390 ms 20200 KB
// author : sentheta aka vanwij
#ifdef VANWIJ
	#include"/home/user/code/bits/stdc++.h"
#else
	#include"bits/stdc++.h"
#endif
using namespace std;

#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second

static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))

#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;

#define int long long
// const Int MOD = 1e9+7;
const Int MOD = 998244353;
Int bpow(Int a,Int b){
	Int ret = 1;
	for(;b; a=a*a%MOD,b/=2) if(b&1) ret = ret*a%MOD;
	return ret;
}
Int inv(Int a){return bpow(a,MOD-2);}

void solve(); int TC, ALLTC;
signed main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(7);
	// cin >> ALLTC; for(TC=1; TC<=ALLTC; TC++) solve(); return 0;
	solve();
}













const int N = 1<<18;

int lg, n, q;
string s;

int sub[N], super[N];

void solve1(){
	string t;
	cin >> t;
	reverse(all(t));
	// dbg(t);

	int a=0, b=0, c=0;
	rep(i,0,lg){
		if(t[i]=='0') a |= 1<<i;
		if(t[i]=='1') b |= 1<<i;
		if(t[i]=='?') c |= 1<<i;
	}
	// dbg(a); dbg(b); dbg(c);

	int ans = 0;
	if(bitcnt(a) <= 6){
		for(int z=a; ; z=(z-1)&a){
			int amt = super[b|z];
			if(bitcnt(z)&1) amt *= -1;
			ans += amt;

			if(z==0) break;
		}
	}
	else
	if(bitcnt(b) <= 6){
		for(int z=b; ; z=(z-1)&b){
			int amt = sub[c|z];
			if(bitcnt(z^b)&1) amt *= -1;
			ans += amt;

			if(z==0) break;
		}
	}
	else
	if(bitcnt(c) <= 6){
		for(int z=c; ; z=(z-1)&c){
			ans += s[b|z]-'0';

			if(z==0) break;
		}
	}

	cout << ans << nl;
}

void solve(){
	
	cin >> lg >> q >> s;
	n = 1<<lg;
	
	rep(i,0,n){
		sub[i] = super[i] = s[i]-'0';
	}

	rep(b,0,lg) rep(msk,0,n){
		// include submask
		if(msk&1<<b){
			sub[msk] += sub[msk^1<<b];
		}
		// include supermask
		else{
			super[msk] += super[msk^1<<b];
		}
	}
	
	while(q--){
		solve1();
	}
	
	
	
	
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 336 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 344 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 336 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 171 ms 15020 KB Output is correct
12 Correct 241 ms 14756 KB Output is correct
13 Correct 284 ms 13988 KB Output is correct
14 Correct 233 ms 14092 KB Output is correct
15 Correct 216 ms 15032 KB Output is correct
16 Correct 220 ms 14256 KB Output is correct
17 Correct 235 ms 14144 KB Output is correct
18 Correct 149 ms 16072 KB Output is correct
19 Correct 253 ms 13016 KB Output is correct
20 Correct 180 ms 14668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 336 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 171 ms 15020 KB Output is correct
12 Correct 241 ms 14756 KB Output is correct
13 Correct 284 ms 13988 KB Output is correct
14 Correct 233 ms 14092 KB Output is correct
15 Correct 216 ms 15032 KB Output is correct
16 Correct 220 ms 14256 KB Output is correct
17 Correct 235 ms 14144 KB Output is correct
18 Correct 149 ms 16072 KB Output is correct
19 Correct 253 ms 13016 KB Output is correct
20 Correct 180 ms 14668 KB Output is correct
21 Correct 192 ms 18128 KB Output is correct
22 Correct 263 ms 18352 KB Output is correct
23 Correct 390 ms 17388 KB Output is correct
24 Correct 298 ms 17204 KB Output is correct
25 Correct 223 ms 19164 KB Output is correct
26 Correct 264 ms 17660 KB Output is correct
27 Correct 303 ms 17648 KB Output is correct
28 Correct 155 ms 20200 KB Output is correct
29 Correct 350 ms 16128 KB Output is correct
30 Correct 218 ms 18352 KB Output is correct
31 Correct 264 ms 18160 KB Output is correct
32 Correct 278 ms 18148 KB Output is correct
33 Correct 265 ms 17044 KB Output is correct
34 Correct 331 ms 17108 KB Output is correct
35 Correct 312 ms 17532 KB Output is correct
36 Correct 172 ms 16100 KB Output is correct
37 Correct 225 ms 18200 KB Output is correct
38 Correct 331 ms 16128 KB Output is correct
39 Correct 265 ms 17448 KB Output is correct
40 Correct 273 ms 17104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 336 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 19 ms 12408 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 336 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 171 ms 15020 KB Output is correct
12 Correct 241 ms 14756 KB Output is correct
13 Correct 284 ms 13988 KB Output is correct
14 Correct 233 ms 14092 KB Output is correct
15 Correct 216 ms 15032 KB Output is correct
16 Correct 220 ms 14256 KB Output is correct
17 Correct 235 ms 14144 KB Output is correct
18 Correct 149 ms 16072 KB Output is correct
19 Correct 253 ms 13016 KB Output is correct
20 Correct 180 ms 14668 KB Output is correct
21 Correct 192 ms 18128 KB Output is correct
22 Correct 263 ms 18352 KB Output is correct
23 Correct 390 ms 17388 KB Output is correct
24 Correct 298 ms 17204 KB Output is correct
25 Correct 223 ms 19164 KB Output is correct
26 Correct 264 ms 17660 KB Output is correct
27 Correct 303 ms 17648 KB Output is correct
28 Correct 155 ms 20200 KB Output is correct
29 Correct 350 ms 16128 KB Output is correct
30 Correct 218 ms 18352 KB Output is correct
31 Correct 264 ms 18160 KB Output is correct
32 Correct 278 ms 18148 KB Output is correct
33 Correct 265 ms 17044 KB Output is correct
34 Correct 331 ms 17108 KB Output is correct
35 Correct 312 ms 17532 KB Output is correct
36 Correct 172 ms 16100 KB Output is correct
37 Correct 225 ms 18200 KB Output is correct
38 Correct 331 ms 16128 KB Output is correct
39 Correct 265 ms 17448 KB Output is correct
40 Correct 273 ms 17104 KB Output is correct
41 Runtime error 19 ms 12408 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -