답안 #763112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763112 2023-06-22T03:51:33 Z sentheta Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
682 ms 39232 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<<20;

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();
	}
	
	
	
	
}
# 결과 실행 시간 메모리 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 344 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
# 결과 실행 시간 메모리 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 344 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 174 ms 12672 KB Output is correct
12 Correct 241 ms 12240 KB Output is correct
13 Correct 272 ms 11588 KB Output is correct
14 Correct 233 ms 11616 KB Output is correct
15 Correct 187 ms 12628 KB Output is correct
16 Correct 220 ms 11912 KB Output is correct
17 Correct 247 ms 11796 KB Output is correct
18 Correct 137 ms 13672 KB Output is correct
19 Correct 242 ms 10624 KB Output is correct
20 Correct 174 ms 12368 KB Output is correct
# 결과 실행 시간 메모리 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 344 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 174 ms 12672 KB Output is correct
12 Correct 241 ms 12240 KB Output is correct
13 Correct 272 ms 11588 KB Output is correct
14 Correct 233 ms 11616 KB Output is correct
15 Correct 187 ms 12628 KB Output is correct
16 Correct 220 ms 11912 KB Output is correct
17 Correct 247 ms 11796 KB Output is correct
18 Correct 137 ms 13672 KB Output is correct
19 Correct 242 ms 10624 KB Output is correct
20 Correct 174 ms 12368 KB Output is correct
21 Correct 197 ms 12680 KB Output is correct
22 Correct 260 ms 12984 KB Output is correct
23 Correct 388 ms 11908 KB Output is correct
24 Correct 305 ms 11712 KB Output is correct
25 Correct 216 ms 13644 KB Output is correct
26 Correct 272 ms 12236 KB Output is correct
27 Correct 295 ms 12096 KB Output is correct
28 Correct 146 ms 14540 KB Output is correct
29 Correct 353 ms 10436 KB Output is correct
30 Correct 203 ms 12620 KB Output is correct
31 Correct 272 ms 12480 KB Output is correct
32 Correct 261 ms 12112 KB Output is correct
33 Correct 224 ms 10768 KB Output is correct
34 Correct 315 ms 10724 KB Output is correct
35 Correct 291 ms 10992 KB Output is correct
36 Correct 156 ms 9348 KB Output is correct
37 Correct 184 ms 11196 KB Output is correct
38 Correct 310 ms 8832 KB Output is correct
39 Correct 261 ms 9816 KB Output is correct
40 Correct 259 ms 9416 KB Output is correct
# 결과 실행 시간 메모리 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 344 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 36 ms 11868 KB Output is correct
12 Correct 47 ms 11884 KB Output is correct
13 Correct 45 ms 11852 KB Output is correct
14 Correct 53 ms 11884 KB Output is correct
15 Correct 46 ms 12032 KB Output is correct
16 Correct 50 ms 11884 KB Output is correct
17 Correct 51 ms 11944 KB Output is correct
18 Correct 33 ms 12084 KB Output is correct
19 Correct 44 ms 11844 KB Output is correct
20 Correct 37 ms 11948 KB Output is correct
21 Correct 45 ms 11964 KB Output is correct
22 Correct 48 ms 11848 KB Output is correct
23 Correct 39 ms 11864 KB Output is correct
24 Correct 49 ms 11828 KB Output is correct
25 Correct 46 ms 11884 KB Output is correct
26 Correct 32 ms 11756 KB Output is correct
27 Correct 35 ms 11956 KB Output is correct
28 Correct 41 ms 11756 KB Output is correct
29 Correct 42 ms 11852 KB Output is correct
30 Correct 46 ms 11860 KB Output is correct
31 Correct 42 ms 11764 KB Output is correct
32 Correct 64 ms 11940 KB Output is correct
33 Correct 51 ms 11820 KB Output is correct
34 Correct 33 ms 11720 KB Output is correct
35 Correct 47 ms 11848 KB Output is correct
36 Correct 48 ms 11880 KB Output is correct
37 Correct 43 ms 11848 KB Output is correct
38 Correct 42 ms 11848 KB Output is correct
39 Correct 47 ms 11936 KB Output is correct
40 Correct 44 ms 11932 KB Output is correct
# 결과 실행 시간 메모리 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 344 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 174 ms 12672 KB Output is correct
12 Correct 241 ms 12240 KB Output is correct
13 Correct 272 ms 11588 KB Output is correct
14 Correct 233 ms 11616 KB Output is correct
15 Correct 187 ms 12628 KB Output is correct
16 Correct 220 ms 11912 KB Output is correct
17 Correct 247 ms 11796 KB Output is correct
18 Correct 137 ms 13672 KB Output is correct
19 Correct 242 ms 10624 KB Output is correct
20 Correct 174 ms 12368 KB Output is correct
21 Correct 197 ms 12680 KB Output is correct
22 Correct 260 ms 12984 KB Output is correct
23 Correct 388 ms 11908 KB Output is correct
24 Correct 305 ms 11712 KB Output is correct
25 Correct 216 ms 13644 KB Output is correct
26 Correct 272 ms 12236 KB Output is correct
27 Correct 295 ms 12096 KB Output is correct
28 Correct 146 ms 14540 KB Output is correct
29 Correct 353 ms 10436 KB Output is correct
30 Correct 203 ms 12620 KB Output is correct
31 Correct 272 ms 12480 KB Output is correct
32 Correct 261 ms 12112 KB Output is correct
33 Correct 224 ms 10768 KB Output is correct
34 Correct 315 ms 10724 KB Output is correct
35 Correct 291 ms 10992 KB Output is correct
36 Correct 156 ms 9348 KB Output is correct
37 Correct 184 ms 11196 KB Output is correct
38 Correct 310 ms 8832 KB Output is correct
39 Correct 261 ms 9816 KB Output is correct
40 Correct 259 ms 9416 KB Output is correct
41 Correct 36 ms 11868 KB Output is correct
42 Correct 47 ms 11884 KB Output is correct
43 Correct 45 ms 11852 KB Output is correct
44 Correct 53 ms 11884 KB Output is correct
45 Correct 46 ms 12032 KB Output is correct
46 Correct 50 ms 11884 KB Output is correct
47 Correct 51 ms 11944 KB Output is correct
48 Correct 33 ms 12084 KB Output is correct
49 Correct 44 ms 11844 KB Output is correct
50 Correct 37 ms 11948 KB Output is correct
51 Correct 45 ms 11964 KB Output is correct
52 Correct 48 ms 11848 KB Output is correct
53 Correct 39 ms 11864 KB Output is correct
54 Correct 49 ms 11828 KB Output is correct
55 Correct 46 ms 11884 KB Output is correct
56 Correct 32 ms 11756 KB Output is correct
57 Correct 35 ms 11956 KB Output is correct
58 Correct 41 ms 11756 KB Output is correct
59 Correct 42 ms 11852 KB Output is correct
60 Correct 46 ms 11860 KB Output is correct
61 Correct 42 ms 11764 KB Output is correct
62 Correct 64 ms 11940 KB Output is correct
63 Correct 51 ms 11820 KB Output is correct
64 Correct 33 ms 11720 KB Output is correct
65 Correct 47 ms 11848 KB Output is correct
66 Correct 48 ms 11880 KB Output is correct
67 Correct 43 ms 11848 KB Output is correct
68 Correct 42 ms 11848 KB Output is correct
69 Correct 47 ms 11936 KB Output is correct
70 Correct 44 ms 11932 KB Output is correct
71 Correct 316 ms 36188 KB Output is correct
72 Correct 332 ms 36416 KB Output is correct
73 Correct 460 ms 34888 KB Output is correct
74 Correct 630 ms 35176 KB Output is correct
75 Correct 363 ms 37268 KB Output is correct
76 Correct 592 ms 35564 KB Output is correct
77 Correct 571 ms 35436 KB Output is correct
78 Correct 264 ms 39232 KB Output is correct
79 Correct 318 ms 33192 KB Output is correct
80 Correct 357 ms 36324 KB Output is correct
81 Correct 468 ms 36260 KB Output is correct
82 Correct 659 ms 35288 KB Output is correct
83 Correct 365 ms 34344 KB Output is correct
84 Correct 616 ms 35240 KB Output is correct
85 Correct 599 ms 35404 KB Output is correct
86 Correct 316 ms 33240 KB Output is correct
87 Correct 369 ms 36256 KB Output is correct
88 Correct 368 ms 33180 KB Output is correct
89 Correct 539 ms 34804 KB Output is correct
90 Correct 474 ms 35304 KB Output is correct
91 Correct 497 ms 34340 KB Output is correct
92 Correct 651 ms 35548 KB Output is correct
93 Correct 618 ms 35444 KB Output is correct
94 Correct 209 ms 33180 KB Output is correct
95 Correct 582 ms 35372 KB Output is correct
96 Correct 589 ms 35236 KB Output is correct
97 Correct 509 ms 35324 KB Output is correct
98 Correct 682 ms 35288 KB Output is correct
99 Correct 605 ms 35256 KB Output is correct
100 Correct 588 ms 35332 KB Output is correct