Submission #66915

# Submission time Handle Problem Language Result Execution time Memory
66915 2018-08-12T19:08:30 Z hamzqq9 Snake Escaping (JOI18_snake_escaping) C++14
0 / 100
502 ms 13432 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 100000000000000
#define MOD 1000000007
#define N 3005
#define MAX 10000006
#define LOG 22
#define L 7
#define R 13
using namespace std;
 
int n,q,l;
int cnt[1594325],ans[pw(20)+5];
int po3[20],pos[1594325];
char val[pw(20)+5],s[pw(20)+5];
bool oops[1594325],inc[2188][129];
short Left[pw(20)+5],Right[pw(20)+5];
 
int get_2_rep(int val) {
 
	int res=0;
	int curpw=1;
 
	while(val) {
 
		res+=curpw*(val%3);
 
		val/=3;
 
		curpw*=2;
 
	}
 
	return res;
 
}
 
int get_2(int val) {
 
	int cur=0;
 
	while(val) {
 
		if(val%3==2) return cur;
 
		cur++;
 
		val/=3;
 
	}
 
	return -1;
 
}
 
void do_dp(int value) {
 
	for(int i=0;i<1594323;i++) {
 
		if(oops[i]) cnt[i]=val[value*pw(R)+pos[i]];
		else cnt[i]=cnt[i-po3[pos[i]]]+cnt[i-2*po3[pos[i]]];
 
	}
 
}

int lval,rval;

void back_track(int bit) {

	if(bit==L) {

		inc[rval][lval]=false;

		return ;

	}

	lval+=pw(bit);

	back_track(bit+1);

	lval-=pw(bit);

	rval+=po3[bit];

	back_track(bit+1);

	rval-=po3[bit];

}

void pre_cal() {
 
	for(int i=0;i<1594323;i++) {
 
		pos[i]=get_2(i);
 
		if(pos[i]==-1) {
		
			oops[i]=true;
 
			pos[i]=get_2_rep(i);
		
		}
 
	}

	for(int i=0;i<2188;i++) for(int j=0;j<129;j++) inc[i][j]=true;

	back_track(0);
 
}
 
int get_value(int bas,int son) {
 
	int res=0;
 
	for(int i=bas;i<=son;i++) {
 
		res=res*3+(s[i]=='?'?2:(s[i]-'0'));
 
	}
 
	return res;
 
}
 
int main() {
 
	//freopen("input.txt","r",stdin);
 
	po3[0]=1;
 
 	for(int i=1;i<=15;i++) po3[i]=po3[i-1]*3;
 
	scanf("%d %d",&l,&q);
 
	n=pw(l);
 
	scanf("%s",s);
 
	for(int i=0;i<n;i++) val[i]=s[i]-'0';
 
	for(int i=1;i<=q;i++) {
 
		scanf("%s",s+20-l);
 
		for(int i=0;i<20-l;i++) s[i]='0';
 
		Right[i]=get_value(7,19);
		Left[i]=get_value(0,6);
 
	}
 
	pre_cal();
 
	for(int i=0;i<pw(L);i++) {
 
		do_dp(i);
 
		for(int j=1;j<=q;j++) {

			if(inc[Left[j]][i]) {

				ans[j]+=cnt[Right[j]];

			}

		}
 
	}
 
	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
 
} 	

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:151:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&l,&q);
  ~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:155:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s);
  ~~~~~^~~~~~~~
snake_escaping.cpp:161:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",s+20-l);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 502 ms 13432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 502 ms 13432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 502 ms 13432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 502 ms 13432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 502 ms 13432 KB Output isn't correct
2 Halted 0 ms 0 KB -