Submission #41281

# Submission time Handle Problem Language Result Execution time Memory
41281 2018-02-15T11:06:10 Z Kerim Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
473 ms 65536 KB
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx") 
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
#define BLOK 14
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int n,q;
const int N=(1<<20)+5;
int arr[N];
int dp[N*2],pw[22],ans[N];
char s[N],t[22];
vector<PII>adj[22];
bitset<N>ok[130];
void rec(int pos,int mask,int bit,int last){
	if(pos==min(n,BLOK)){
		adj[bit].pb(mp(mask,last));
		return;
	}
	rec(pos+1,mask*3,bit,last);
	rec(pos+1,mask*3+1,bit,last);
	rec(pos+1,mask*3+2,bit+1,min(n,BLOK)-pos-1);
}
int two(int x){
	int bit=0,res=0;
	while(x>=1){
		assert(x%3<2);
		if(x%3)
			res+=(1<<bit);
		x/=3;bit++;
	}
	return res;
}
void f(int l,int r,int mask,int ind){
	if(l==r){
		ok[mask][ind]=1;
		//~ query[mask].pb(mp(suf,ind));
		return;
	}
	if(t[l]=='0')
		f(l+1,r,mask*2,ind);
	if(t[l]=='1')
		f(l+1,r,mask*2+1,ind);
	if(t[l]=='?'){
		f(l+1,r,mask*2,ind);
		f(l+1,r,mask*2+1,ind);
	}	
}
int main(){
    //~ freopen("file.in", "r", stdin);
    scanf("%d%d",&n,&q);
    scanf("%s",s);
    pw[0]=1;
    for(int i=1;i<=BLOK;i++)
		pw[i]=pw[i-1]*3;
    if(n<=BLOK){
		rec(0,0,0,-1);
		tr(it,adj[0])
			dp[it->ff]=s[two(it->ff)]-'0';
		for(int j=1;j<=n;j++)
			tr(it,adj[j])
				dp[it->ff]=dp[it->ff-pw[it->ss]]+dp[it->ff-2*pw[it->ss]];
		for(int i=1;i<=q;i++){
			scanf("%s",t);
			int base=0;
			for(int j=0;j<n;j++){
				base=base*3;
				if(t[j]=='1')
					base++;
				if(t[j]=='?')
					base+=2;
			}
			printf("%d\n",dp[base]);
		}
	}
	else{
		rec(0,0,0,-1);
		for(int i=1;i<=q;i++){
			scanf("%s",t);
			int base=0;
			for(int j=n-BLOK;j<n;j++){
				base=base*3;
				if(t[j]=='1')
					base++;
				if(t[j]=='?')
					base+=2;
			}
			f(0,n-BLOK,0,i);arr[i]=base;
		}
		int lek=(1<<BLOK);
		for(int mask=0;mask<(1<<(n-BLOK));mask++){
			tr(it,adj[0])
				dp[it->ff]=s[lek*mask+two(it->ff)]-'0';
			for(int i=1;i<=BLOK;i++)
				tr(it,adj[i])
					dp[it->ff]=dp[it->ff-pw[it->ss]]+dp[it->ff-2*pw[it->ss]];
			for(int i=1;i<=q;i++)
				if(ok[mask][i])
					ans[i]+=dp[arr[i]];
		}
		for(int i=1;i<=q;i++)
			printf("%d\n",ans[i]);
	}
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:70:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&q);
                        ^
snake_escaping.cpp:71:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",s);
                  ^
snake_escaping.cpp:83:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%s",t);
                 ^
snake_escaping.cpp:98:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%s",t);
                 ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1260 KB Output is correct
3 Correct 3 ms 1472 KB Output is correct
4 Correct 3 ms 1472 KB Output is correct
5 Correct 3 ms 1636 KB Output is correct
6 Correct 4 ms 1636 KB Output is correct
7 Correct 3 ms 1636 KB Output is correct
8 Correct 3 ms 1648 KB Output is correct
9 Correct 4 ms 1648 KB Output is correct
10 Correct 3 ms 1648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1260 KB Output is correct
3 Correct 3 ms 1472 KB Output is correct
4 Correct 3 ms 1472 KB Output is correct
5 Correct 3 ms 1636 KB Output is correct
6 Correct 4 ms 1636 KB Output is correct
7 Correct 3 ms 1636 KB Output is correct
8 Correct 3 ms 1648 KB Output is correct
9 Correct 4 ms 1648 KB Output is correct
10 Correct 3 ms 1648 KB Output is correct
11 Correct 266 ms 16312 KB Output is correct
12 Correct 234 ms 26732 KB Output is correct
13 Correct 266 ms 36724 KB Output is correct
14 Correct 254 ms 47552 KB Output is correct
15 Correct 238 ms 59252 KB Output is correct
16 Correct 258 ms 65536 KB Output is correct
17 Correct 289 ms 65536 KB Output is correct
18 Correct 235 ms 65536 KB Output is correct
19 Correct 268 ms 65536 KB Output is correct
20 Correct 274 ms 65536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1260 KB Output is correct
3 Correct 3 ms 1472 KB Output is correct
4 Correct 3 ms 1472 KB Output is correct
5 Correct 3 ms 1636 KB Output is correct
6 Correct 4 ms 1636 KB Output is correct
7 Correct 3 ms 1636 KB Output is correct
8 Correct 3 ms 1648 KB Output is correct
9 Correct 4 ms 1648 KB Output is correct
10 Correct 3 ms 1648 KB Output is correct
11 Correct 266 ms 16312 KB Output is correct
12 Correct 234 ms 26732 KB Output is correct
13 Correct 266 ms 36724 KB Output is correct
14 Correct 254 ms 47552 KB Output is correct
15 Correct 238 ms 59252 KB Output is correct
16 Correct 258 ms 65536 KB Output is correct
17 Correct 289 ms 65536 KB Output is correct
18 Correct 235 ms 65536 KB Output is correct
19 Correct 268 ms 65536 KB Output is correct
20 Correct 274 ms 65536 KB Output is correct
21 Correct 387 ms 65536 KB Output is correct
22 Correct 309 ms 65536 KB Output is correct
23 Correct 428 ms 65536 KB Output is correct
24 Correct 421 ms 65536 KB Output is correct
25 Correct 352 ms 65536 KB Output is correct
26 Correct 449 ms 65536 KB Output is correct
27 Correct 470 ms 65536 KB Output is correct
28 Correct 295 ms 65536 KB Output is correct
29 Correct 358 ms 65536 KB Output is correct
30 Correct 374 ms 65536 KB Output is correct
31 Correct 414 ms 65536 KB Output is correct
32 Correct 460 ms 65536 KB Output is correct
33 Correct 374 ms 65536 KB Output is correct
34 Correct 455 ms 65536 KB Output is correct
35 Correct 463 ms 65536 KB Output is correct
36 Correct 299 ms 65536 KB Output is correct
37 Correct 289 ms 65536 KB Output is correct
38 Correct 403 ms 65536 KB Output is correct
39 Correct 473 ms 65536 KB Output is correct
40 Correct 434 ms 65536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1260 KB Output is correct
3 Correct 3 ms 1472 KB Output is correct
4 Correct 3 ms 1472 KB Output is correct
5 Correct 3 ms 1636 KB Output is correct
6 Correct 4 ms 1636 KB Output is correct
7 Correct 3 ms 1636 KB Output is correct
8 Correct 3 ms 1648 KB Output is correct
9 Correct 4 ms 1648 KB Output is correct
10 Correct 3 ms 1648 KB Output is correct
11 Runtime error 89 ms 65536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1260 KB Output is correct
3 Correct 3 ms 1472 KB Output is correct
4 Correct 3 ms 1472 KB Output is correct
5 Correct 3 ms 1636 KB Output is correct
6 Correct 4 ms 1636 KB Output is correct
7 Correct 3 ms 1636 KB Output is correct
8 Correct 3 ms 1648 KB Output is correct
9 Correct 4 ms 1648 KB Output is correct
10 Correct 3 ms 1648 KB Output is correct
11 Correct 266 ms 16312 KB Output is correct
12 Correct 234 ms 26732 KB Output is correct
13 Correct 266 ms 36724 KB Output is correct
14 Correct 254 ms 47552 KB Output is correct
15 Correct 238 ms 59252 KB Output is correct
16 Correct 258 ms 65536 KB Output is correct
17 Correct 289 ms 65536 KB Output is correct
18 Correct 235 ms 65536 KB Output is correct
19 Correct 268 ms 65536 KB Output is correct
20 Correct 274 ms 65536 KB Output is correct
21 Correct 387 ms 65536 KB Output is correct
22 Correct 309 ms 65536 KB Output is correct
23 Correct 428 ms 65536 KB Output is correct
24 Correct 421 ms 65536 KB Output is correct
25 Correct 352 ms 65536 KB Output is correct
26 Correct 449 ms 65536 KB Output is correct
27 Correct 470 ms 65536 KB Output is correct
28 Correct 295 ms 65536 KB Output is correct
29 Correct 358 ms 65536 KB Output is correct
30 Correct 374 ms 65536 KB Output is correct
31 Correct 414 ms 65536 KB Output is correct
32 Correct 460 ms 65536 KB Output is correct
33 Correct 374 ms 65536 KB Output is correct
34 Correct 455 ms 65536 KB Output is correct
35 Correct 463 ms 65536 KB Output is correct
36 Correct 299 ms 65536 KB Output is correct
37 Correct 289 ms 65536 KB Output is correct
38 Correct 403 ms 65536 KB Output is correct
39 Correct 473 ms 65536 KB Output is correct
40 Correct 434 ms 65536 KB Output is correct
41 Runtime error 89 ms 65536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Halted 0 ms 0 KB -