답안 #210540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210540 2020-03-17T16:22:31 Z kshitij_sodani Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
692 ms 40184 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long llo;
#define a first
#define  b second
#define endl "\n"
int aa=7;
//vector<int> aac[1000001];

//vector<int> pre[16000];
int sl3[21];
int sl[22];
int l;
int dp[1600000];//3^13
int last[1600000];//3^13
int ans[1000001];//q
int it[1100001];//n
int num[1000001];//q
int ok;
/*void find(int ind,int tot,int ind2){//pre_sub
	if(ind==aa){
		pre[tot].pb(ind2);
	//	cout<<tot<<" "<<ind2<<endl;
	}
	else{
		if(aac[ind2][ind]%2==0){
			find(ind+1,tot,ind2);
		}
		if(aac[ind2][ind]>0){
			find(ind+1,tot+sl[aa-ind-1],ind2);
		}
	}
}*/
void find2(int ind,int ind2,int tot=0){//
	if(ind==l-aa){
		last[tot]=ind2;
	//	cout<<tot<<","<<ind2<<endl;
		return;
	}
	if(ind==ind2){
		find2(ind+1,ind2,tot+2*sl3[(l-aa)-ind-1]);
	}
	else{
		find2(ind+1,ind2,tot);
		find2(ind+1,ind2,tot+sl3[(l-aa)-ind-1]);
	}
	if(ind<ind2){
		find2(ind+1,ind2,tot+2*sl3[(l-aa)-ind-1]);
	}
}
int find3(int ind,int ind3=0){//dp
	if(dp[ind]>-1){
		return dp[ind];
	}
		//cout<<ind<<" ";
	if(last[ind]==-1){
		dp[ind]=it[ind3];
		return dp[ind];
	}
	dp[ind]=find3(ind-sl3[l-aa-last[ind]-1],ind3+sl[l-aa-last[ind]-1])+find3(ind-2*sl3[l-aa-last[ind]-1],ind3);
	return dp[ind];
}
//void(int)
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(last,-1,sizeof(last));
	memset(num,0,sizeof(num));
	sl[0]=1;
	for(int i=1;i<22;i++){
		sl[i]=2*sl[i-1];
	}
	sl3[0]=1;
	for(int i=1;i<14;i++){
		sl3[i]=3*sl3[i-1];
	}

	int q;
	cin>>l>>q;
	aa=0;
	int n=sl[l];
	
	char ss;
	for(int i=0;i<n;i++){
		cin>>ss;
		it[i]=ss-'0';
	}
	

	for(int ii=0;ii<q;ii++){
		for(int i=0;i<l;i++){
			cin>>ss;
			if(ss=='0'){
			//	aac[ii].pb(0);
				if(l==1){
					cout<<it[0]<<endl;
				}
				
			}
			else if(ss=='1'){
			//	aac[ii].pb(1);
				if(l==1){
					cout<<it[1]<<endl;
				}
				else{
				//	if(i>=aa){
						num[ii]+=sl3[l-i-1];
				//	}
				} 
			}
			else{
			//	aac[ii].pb(2);
				if(l==1){
					cout<<it[0]+it[1]<<endl;
				}
				else{
				//	if(i>=aa){
						num[ii]+=2*sl3[l-i-1];
				//	}
				}
			}
		}
	}
	/*for(int i=0;i<q;i++){
		cout<<num[i]<<" ";
	}
	cout<<endl;*/
	if(l==1){
		return 0;
	}
	/*for(int i=0;i<q;i++){
		find((int)0,(int)0,i);
	}*/
	memset(ans,(int)0,sizeof(ans));
	for(int i=0;i<l-aa;i++){
		find2(0,i,0);
	}

	memset(dp,-1,sizeof(dp));
	//find3(8);
	for(int j=1600000-1;j>=0;j--){
		
		int jj=j;
		int ind5=0;
		int sp=0;
		while(jj){
			if(jj%3==1){
				sp+=sl[ind5];
			}
			jj/=3;
			ind5+=1;
		}

find3(j,sp);
		/*if(j==10){
			cout<<dp[8]<<endl;
		}*/
	}
	/*for(int i=0;i<1;i++){
		ok=i;
		if(pre[i].size()){

			memset(dp,(int)-1,sizeof(dp));
			for(int j=0;j<1600000;j++){
				find3(j);
			}
			for(auto j:pre[i]){
				ans[j]+=it[i];
				//ans[j]+=dp[num[j]];
			//	cout<<i<<":"<<j<<":"<<dp[num[j]]<<endl;

			}
		}

	}*/
	for(int i=0;i<q;i++){
		int jj=num[i];
		int ind5=0;
		int sp=0;
		while(jj){
			if(jj%3==1){
				sp+=sl[ind5];
			}
			jj/=3;
			ind5+=1;
		}


		cout<<find3(num[i],sp)<<endl;
	}









	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 20728 KB Output is correct
2 Correct 102 ms 20728 KB Output is correct
3 Correct 101 ms 20728 KB Output is correct
4 Correct 104 ms 20732 KB Output is correct
5 Correct 102 ms 20728 KB Output is correct
6 Correct 102 ms 20748 KB Output is correct
7 Correct 101 ms 20728 KB Output is correct
8 Correct 101 ms 20856 KB Output is correct
9 Correct 103 ms 20728 KB Output is correct
10 Correct 102 ms 20728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 20728 KB Output is correct
2 Correct 102 ms 20728 KB Output is correct
3 Correct 101 ms 20728 KB Output is correct
4 Correct 104 ms 20732 KB Output is correct
5 Correct 102 ms 20728 KB Output is correct
6 Correct 102 ms 20748 KB Output is correct
7 Correct 101 ms 20728 KB Output is correct
8 Correct 101 ms 20856 KB Output is correct
9 Correct 103 ms 20728 KB Output is correct
10 Correct 102 ms 20728 KB Output is correct
11 Correct 485 ms 35448 KB Output is correct
12 Correct 467 ms 35064 KB Output is correct
13 Correct 507 ms 34424 KB Output is correct
14 Correct 520 ms 34428 KB Output is correct
15 Correct 462 ms 35448 KB Output is correct
16 Correct 510 ms 34680 KB Output is correct
17 Correct 517 ms 34556 KB Output is correct
18 Correct 361 ms 36472 KB Output is correct
19 Correct 474 ms 33400 KB Output is correct
20 Correct 511 ms 35132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 20728 KB Output is correct
2 Correct 102 ms 20728 KB Output is correct
3 Correct 101 ms 20728 KB Output is correct
4 Correct 104 ms 20732 KB Output is correct
5 Correct 102 ms 20728 KB Output is correct
6 Correct 102 ms 20748 KB Output is correct
7 Correct 101 ms 20728 KB Output is correct
8 Correct 101 ms 20856 KB Output is correct
9 Correct 103 ms 20728 KB Output is correct
10 Correct 102 ms 20728 KB Output is correct
11 Correct 485 ms 35448 KB Output is correct
12 Correct 467 ms 35064 KB Output is correct
13 Correct 507 ms 34424 KB Output is correct
14 Correct 520 ms 34428 KB Output is correct
15 Correct 462 ms 35448 KB Output is correct
16 Correct 510 ms 34680 KB Output is correct
17 Correct 517 ms 34556 KB Output is correct
18 Correct 361 ms 36472 KB Output is correct
19 Correct 474 ms 33400 KB Output is correct
20 Correct 511 ms 35132 KB Output is correct
21 Correct 601 ms 37368 KB Output is correct
22 Correct 543 ms 35320 KB Output is correct
23 Correct 647 ms 34424 KB Output is correct
24 Correct 635 ms 34140 KB Output is correct
25 Correct 563 ms 36216 KB Output is correct
26 Correct 655 ms 36828 KB Output is correct
27 Correct 670 ms 37624 KB Output is correct
28 Correct 454 ms 40184 KB Output is correct
29 Correct 597 ms 35964 KB Output is correct
30 Correct 625 ms 38132 KB Output is correct
31 Correct 615 ms 38136 KB Output is correct
32 Correct 650 ms 38056 KB Output is correct
33 Correct 587 ms 37112 KB Output is correct
34 Correct 666 ms 37240 KB Output is correct
35 Correct 692 ms 37752 KB Output is correct
36 Correct 438 ms 36344 KB Output is correct
37 Correct 548 ms 38136 KB Output is correct
38 Correct 625 ms 36216 KB Output is correct
39 Correct 648 ms 37372 KB Output is correct
40 Correct 642 ms 37368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 20728 KB Output is correct
2 Correct 102 ms 20728 KB Output is correct
3 Correct 101 ms 20728 KB Output is correct
4 Correct 104 ms 20732 KB Output is correct
5 Correct 102 ms 20728 KB Output is correct
6 Correct 102 ms 20748 KB Output is correct
7 Correct 101 ms 20728 KB Output is correct
8 Correct 101 ms 20856 KB Output is correct
9 Correct 103 ms 20728 KB Output is correct
10 Correct 102 ms 20728 KB Output is correct
11 Runtime error 184 ms 39928 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 20728 KB Output is correct
2 Correct 102 ms 20728 KB Output is correct
3 Correct 101 ms 20728 KB Output is correct
4 Correct 104 ms 20732 KB Output is correct
5 Correct 102 ms 20728 KB Output is correct
6 Correct 102 ms 20748 KB Output is correct
7 Correct 101 ms 20728 KB Output is correct
8 Correct 101 ms 20856 KB Output is correct
9 Correct 103 ms 20728 KB Output is correct
10 Correct 102 ms 20728 KB Output is correct
11 Correct 485 ms 35448 KB Output is correct
12 Correct 467 ms 35064 KB Output is correct
13 Correct 507 ms 34424 KB Output is correct
14 Correct 520 ms 34428 KB Output is correct
15 Correct 462 ms 35448 KB Output is correct
16 Correct 510 ms 34680 KB Output is correct
17 Correct 517 ms 34556 KB Output is correct
18 Correct 361 ms 36472 KB Output is correct
19 Correct 474 ms 33400 KB Output is correct
20 Correct 511 ms 35132 KB Output is correct
21 Correct 601 ms 37368 KB Output is correct
22 Correct 543 ms 35320 KB Output is correct
23 Correct 647 ms 34424 KB Output is correct
24 Correct 635 ms 34140 KB Output is correct
25 Correct 563 ms 36216 KB Output is correct
26 Correct 655 ms 36828 KB Output is correct
27 Correct 670 ms 37624 KB Output is correct
28 Correct 454 ms 40184 KB Output is correct
29 Correct 597 ms 35964 KB Output is correct
30 Correct 625 ms 38132 KB Output is correct
31 Correct 615 ms 38136 KB Output is correct
32 Correct 650 ms 38056 KB Output is correct
33 Correct 587 ms 37112 KB Output is correct
34 Correct 666 ms 37240 KB Output is correct
35 Correct 692 ms 37752 KB Output is correct
36 Correct 438 ms 36344 KB Output is correct
37 Correct 548 ms 38136 KB Output is correct
38 Correct 625 ms 36216 KB Output is correct
39 Correct 648 ms 37372 KB Output is correct
40 Correct 642 ms 37368 KB Output is correct
41 Runtime error 184 ms 39928 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Halted 0 ms 0 KB -