답안 #386152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386152 2021-04-05T19:56:20 Z CSQ31 Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 25216 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
typedef pair<int,pii> P;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int pw[22];
int main()
{

	owo
	pw[0] = 1;
	for(int i=1;i<=21;i++)pw[i] = pw[i-1]*2;
	int l,q;
	cin>>l>>q;
	vector<int>sub(pw[(l+1)]),sup(pw[(l+1)]);
	string snek;
	for(int i=0;i<pw[l];i++){
		char c;cin>>c;
		sub[i]+=c-'0';
		sup[i]+=c-'0';
		snek+=c;
	}
	for(int i=0;i<l;i++){
		for(int j=0;j<pw[l];j++){
			if(j&pw[i])sub[j]+=sub[j^pw[i]];
			else sup[j]+=sup[j^pw[i]];
		}
	}
	while(q--){
		vector<int>a,b,c;
		string s;cin>>s;
		ll ans = 0;
		for(int i=0;i<l;i++){
			if(s[i] == '?')c.pb(l-i-1);
			else if(s[i] == '0')a.pb(l-i-1);
			else b.pb(l-i-1);
		}
		int mn = min({sz(a),sz(b),sz(c)});
		if(sz(c) == mn){
			ll cur = 0;
			for(int i=0;i<l;i++)if(s[i]=='1')cur+=pw[(l-i-1)];
			for(int i=0;i<pw[sz(c)];i++){
				ll ncur = cur;
				for(int j=0;j<sz(c);j++){
					if(i&pw[j])ncur+=pw[c[j]];
				}
				ans+=snek[ncur]-'0';
			}
		}
		else if(sz(a) == mn){
			ll cur = 0;
			for(int i=0;i<l;i++)if(s[i] == '1')cur+=pw[(l-i-1)];
			for(int i=0;i<pw[sz(a)];i++){
				ll ncur = cur;
				int cnt = 0;
				for(int j=0;j<sz(a);j++){
					if(i&pw[j]){ncur+=pw[a[j]];cnt++;}
				}
				if(cnt&1)ans-=sup[ncur];
				else ans+=sup[ncur];
			}
		}else{
			ll cur = 0;
			for(int i=0;i<l;i++)if(s[i] == '?')cur+=pw[(l-i-1)];
			for(int mask=0;mask<pw[sz(b)];mask++){
				ll ncur = cur;
				int cnt = 0;
				for(int j=0;j<sz(b);j++){
					if(mask&pw[j]){ncur+=pw[b[j]];}
					else cnt++;
				}
				if(cnt&1)ans-=sub[ncur];
				else ans+=sub[ncur];
			}
		}
		cout<<ans<<'\n';
	}
}
	
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 594 ms 4456 KB Output is correct
12 Correct 561 ms 4076 KB Output is correct
13 Correct 625 ms 3308 KB Output is correct
14 Correct 644 ms 3436 KB Output is correct
15 Correct 593 ms 4484 KB Output is correct
16 Correct 675 ms 3820 KB Output is correct
17 Correct 673 ms 3692 KB Output is correct
18 Correct 389 ms 5364 KB Output is correct
19 Correct 582 ms 2412 KB Output is correct
20 Correct 572 ms 4204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 594 ms 4456 KB Output is correct
12 Correct 561 ms 4076 KB Output is correct
13 Correct 625 ms 3308 KB Output is correct
14 Correct 644 ms 3436 KB Output is correct
15 Correct 593 ms 4484 KB Output is correct
16 Correct 675 ms 3820 KB Output is correct
17 Correct 673 ms 3692 KB Output is correct
18 Correct 389 ms 5364 KB Output is correct
19 Correct 582 ms 2412 KB Output is correct
20 Correct 572 ms 4204 KB Output is correct
21 Correct 642 ms 4588 KB Output is correct
22 Correct 676 ms 4716 KB Output is correct
23 Correct 779 ms 3820 KB Output is correct
24 Correct 830 ms 3700 KB Output is correct
25 Correct 695 ms 5740 KB Output is correct
26 Correct 843 ms 4276 KB Output is correct
27 Correct 836 ms 3948 KB Output is correct
28 Correct 403 ms 6508 KB Output is correct
29 Correct 627 ms 2540 KB Output is correct
30 Correct 681 ms 4668 KB Output is correct
31 Correct 802 ms 4588 KB Output is correct
32 Correct 875 ms 4716 KB Output is correct
33 Correct 682 ms 3564 KB Output is correct
34 Correct 823 ms 3692 KB Output is correct
35 Correct 839 ms 3948 KB Output is correct
36 Correct 417 ms 2572 KB Output is correct
37 Correct 635 ms 4460 KB Output is correct
38 Correct 664 ms 2668 KB Output is correct
39 Correct 789 ms 3820 KB Output is correct
40 Correct 822 ms 3564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 119 ms 18852 KB Output is correct
12 Correct 116 ms 18852 KB Output is correct
13 Correct 128 ms 18852 KB Output is correct
14 Correct 157 ms 18852 KB Output is correct
15 Correct 119 ms 18852 KB Output is correct
16 Correct 163 ms 18852 KB Output is correct
17 Correct 157 ms 18852 KB Output is correct
18 Correct 95 ms 18852 KB Output is correct
19 Correct 112 ms 18852 KB Output is correct
20 Correct 114 ms 18852 KB Output is correct
21 Correct 142 ms 18852 KB Output is correct
22 Correct 165 ms 18852 KB Output is correct
23 Correct 114 ms 18852 KB Output is correct
24 Correct 155 ms 18852 KB Output is correct
25 Correct 152 ms 18852 KB Output is correct
26 Correct 92 ms 18852 KB Output is correct
27 Correct 115 ms 18852 KB Output is correct
28 Correct 113 ms 18852 KB Output is correct
29 Correct 129 ms 18852 KB Output is correct
30 Correct 155 ms 18852 KB Output is correct
31 Correct 112 ms 18852 KB Output is correct
32 Correct 175 ms 18852 KB Output is correct
33 Correct 156 ms 18852 KB Output is correct
34 Correct 92 ms 18852 KB Output is correct
35 Correct 143 ms 18852 KB Output is correct
36 Correct 147 ms 18852 KB Output is correct
37 Correct 139 ms 18852 KB Output is correct
38 Correct 139 ms 18852 KB Output is correct
39 Correct 149 ms 18852 KB Output is correct
40 Correct 141 ms 18852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 594 ms 4456 KB Output is correct
12 Correct 561 ms 4076 KB Output is correct
13 Correct 625 ms 3308 KB Output is correct
14 Correct 644 ms 3436 KB Output is correct
15 Correct 593 ms 4484 KB Output is correct
16 Correct 675 ms 3820 KB Output is correct
17 Correct 673 ms 3692 KB Output is correct
18 Correct 389 ms 5364 KB Output is correct
19 Correct 582 ms 2412 KB Output is correct
20 Correct 572 ms 4204 KB Output is correct
21 Correct 642 ms 4588 KB Output is correct
22 Correct 676 ms 4716 KB Output is correct
23 Correct 779 ms 3820 KB Output is correct
24 Correct 830 ms 3700 KB Output is correct
25 Correct 695 ms 5740 KB Output is correct
26 Correct 843 ms 4276 KB Output is correct
27 Correct 836 ms 3948 KB Output is correct
28 Correct 403 ms 6508 KB Output is correct
29 Correct 627 ms 2540 KB Output is correct
30 Correct 681 ms 4668 KB Output is correct
31 Correct 802 ms 4588 KB Output is correct
32 Correct 875 ms 4716 KB Output is correct
33 Correct 682 ms 3564 KB Output is correct
34 Correct 823 ms 3692 KB Output is correct
35 Correct 839 ms 3948 KB Output is correct
36 Correct 417 ms 2572 KB Output is correct
37 Correct 635 ms 4460 KB Output is correct
38 Correct 664 ms 2668 KB Output is correct
39 Correct 789 ms 3820 KB Output is correct
40 Correct 822 ms 3564 KB Output is correct
41 Correct 119 ms 18852 KB Output is correct
42 Correct 116 ms 18852 KB Output is correct
43 Correct 128 ms 18852 KB Output is correct
44 Correct 157 ms 18852 KB Output is correct
45 Correct 119 ms 18852 KB Output is correct
46 Correct 163 ms 18852 KB Output is correct
47 Correct 157 ms 18852 KB Output is correct
48 Correct 95 ms 18852 KB Output is correct
49 Correct 112 ms 18852 KB Output is correct
50 Correct 114 ms 18852 KB Output is correct
51 Correct 142 ms 18852 KB Output is correct
52 Correct 165 ms 18852 KB Output is correct
53 Correct 114 ms 18852 KB Output is correct
54 Correct 155 ms 18852 KB Output is correct
55 Correct 152 ms 18852 KB Output is correct
56 Correct 92 ms 18852 KB Output is correct
57 Correct 115 ms 18852 KB Output is correct
58 Correct 113 ms 18852 KB Output is correct
59 Correct 129 ms 18852 KB Output is correct
60 Correct 155 ms 18852 KB Output is correct
61 Correct 112 ms 18852 KB Output is correct
62 Correct 175 ms 18852 KB Output is correct
63 Correct 156 ms 18852 KB Output is correct
64 Correct 92 ms 18852 KB Output is correct
65 Correct 143 ms 18852 KB Output is correct
66 Correct 147 ms 18852 KB Output is correct
67 Correct 139 ms 18852 KB Output is correct
68 Correct 139 ms 18852 KB Output is correct
69 Correct 149 ms 18852 KB Output is correct
70 Correct 141 ms 18852 KB Output is correct
71 Correct 1016 ms 23008 KB Output is correct
72 Correct 1014 ms 23392 KB Output is correct
73 Correct 1255 ms 21728 KB Output is correct
74 Correct 1864 ms 22240 KB Output is correct
75 Correct 1084 ms 25216 KB Output is correct
76 Execution timed out 2069 ms 23608 KB Time limit exceeded
77 Halted 0 ms 0 KB -