답안 #333966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333966 2020-12-08T04:06:45 Z YJU Snake Escaping (JOI18_snake_escaping) C++14
12 / 100
1632 ms 65540 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e6+5;
const ll K=350;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()

ll dp[N],l,po[N],q,k,ans[N];
string s,a;
vector<pll> que[(1<<12)];

ll get3(ll val,ll ip){
	return (val/po[ip])%3;
}

void cal(ll id){
	REP(i,po[k]){
		ll tx=0,ck=1;
		REP(j,k){
			if(get3(i,k-j-1)==2){
				dp[i]=dp[i-2*po[k-j-1]]+dp[i-po[k-j-1]];
				ck=0;
				break;
			}
			tx=tx*2+get3(i,k-j-1);
		}
		if(ck)dp[i]=s[(id<<k)+tx]-'0';
	}
}

void DFS(ll id,ll le,ll qid,ll tx){
	if(id==l-k){que[le].pb(mp(tx,qid));return ;}
	if(a[id]=='?'){
		DFS(id+1,(le<<1)+1,qid,tx);
		DFS(id+1,(le<<1),qid,tx);
		return;
	}
	if(a[id]=='0')DFS(id+1,(le<<1),qid,tx);
	if(a[id]=='1')DFS(id+1,(le<<1)+1,qid,tx);
	return;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>l>>q;
	cin>>s;
	k=min(l,11LL);
	po[0]=1;
	REP1(i,k)po[i]=po[i-1]*3;
	REP(T,q){
		cin>>a;
		ll tx=0;
		for(int i=l-k;i<l;i++)tx=tx*3+(a[i]=='?'?2:a[i]-'0');
		DFS(0,0,T,tx);
	}
	REP(i,(1<<(l-k))){
		if(SZ(que[i]))cal(i);
		for(auto j:que[i]){
			ans[j.Y]+=dp[j.X];
		}
	}
	REP(i,q)cout<<ans[i]<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1004 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 2 ms 1004 KB Output is correct
4 Correct 2 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 2 ms 1004 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 2 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1004 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 2 ms 1004 KB Output is correct
4 Correct 2 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 2 ms 1004 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 2 ms 1004 KB Output is correct
11 Correct 259 ms 28904 KB Output is correct
12 Correct 268 ms 28216 KB Output is correct
13 Correct 246 ms 27448 KB Output is correct
14 Correct 242 ms 27576 KB Output is correct
15 Correct 255 ms 28644 KB Output is correct
16 Correct 262 ms 27704 KB Output is correct
17 Correct 257 ms 27704 KB Output is correct
18 Correct 219 ms 29624 KB Output is correct
19 Correct 217 ms 26552 KB Output is correct
20 Correct 272 ms 28344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1004 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 2 ms 1004 KB Output is correct
4 Correct 2 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 2 ms 1004 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 2 ms 1004 KB Output is correct
11 Correct 259 ms 28904 KB Output is correct
12 Correct 268 ms 28216 KB Output is correct
13 Correct 246 ms 27448 KB Output is correct
14 Correct 242 ms 27576 KB Output is correct
15 Correct 255 ms 28644 KB Output is correct
16 Correct 262 ms 27704 KB Output is correct
17 Correct 257 ms 27704 KB Output is correct
18 Correct 219 ms 29624 KB Output is correct
19 Correct 217 ms 26552 KB Output is correct
20 Correct 272 ms 28344 KB Output is correct
21 Correct 343 ms 58716 KB Output is correct
22 Correct 343 ms 60076 KB Output is correct
23 Correct 316 ms 38148 KB Output is correct
24 Correct 304 ms 39532 KB Output is correct
25 Correct 354 ms 55644 KB Output is correct
26 Correct 334 ms 41768 KB Output is correct
27 Correct 325 ms 41340 KB Output is correct
28 Runtime error 218 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1004 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 2 ms 1004 KB Output is correct
4 Correct 2 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 2 ms 1004 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 2 ms 1004 KB Output is correct
11 Correct 1632 ms 35980 KB Output is correct
12 Correct 1630 ms 41096 KB Output is correct
13 Correct 1589 ms 11404 KB Output is correct
14 Correct 1588 ms 17316 KB Output is correct
15 Runtime error 142 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1004 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 2 ms 1004 KB Output is correct
4 Correct 2 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 2 ms 1004 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 2 ms 1004 KB Output is correct
11 Correct 259 ms 28904 KB Output is correct
12 Correct 268 ms 28216 KB Output is correct
13 Correct 246 ms 27448 KB Output is correct
14 Correct 242 ms 27576 KB Output is correct
15 Correct 255 ms 28644 KB Output is correct
16 Correct 262 ms 27704 KB Output is correct
17 Correct 257 ms 27704 KB Output is correct
18 Correct 219 ms 29624 KB Output is correct
19 Correct 217 ms 26552 KB Output is correct
20 Correct 272 ms 28344 KB Output is correct
21 Correct 343 ms 58716 KB Output is correct
22 Correct 343 ms 60076 KB Output is correct
23 Correct 316 ms 38148 KB Output is correct
24 Correct 304 ms 39532 KB Output is correct
25 Correct 354 ms 55644 KB Output is correct
26 Correct 334 ms 41768 KB Output is correct
27 Correct 325 ms 41340 KB Output is correct
28 Runtime error 218 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Halted 0 ms 0 KB -