Submission #289846

# Submission time Handle Problem Language Result Execution time Memory
289846 2020-09-03T06:42:16 Z Pyqe Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 31384 KB
#include <bits/stdc++.h>

using namespace std;

int nd,n,d,d2,p3[12],dh[177147],pst[177147],a[1ll<<20],wg[1000000],wgg[1000000],mka[1000000],dp[177147],sq[1000000];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t,rr,i,k,w,mk;
	string s;
	
	cin>>nd>>t;
	n=1ll<<nd;
	d=min(nd,9);
	d2=max(nd-9,0);
	p3[0]=1;
	for(i=1;i<=d2;i++)
	{
		p3[i]=p3[i-1]*3;
	}
	for(mk=0;mk<p3[d2];mk++)
	{
		w=0;
		for(i=d2-1;i+1;i--)
		{
			k=mk/p3[i]%3;
			if(k==2)
			{
				break;
			}
			w=w<<1|k;
		}
		dh[mk]=i;
		if(dh[mk]==-1)
		{
			pst[mk]=w;
		}
	}
	cin>>s;
	for(i=0;i<n;i++)
	{
		a[i]=s[i]-'0';
	}
	for(rr=0;rr<t;rr++)
	{
		cin>>s;
		wg[rr]=0;
		wgg[rr]=0;
		for(i=0;i<d;i++)
		{
			k=(s[i]=='1')+2*(s[i]=='?');
			wg[rr]=wg[rr]<<1|k%2;
			wgg[rr]=wgg[rr]<<1|k<2;
		}
		mka[rr]=0;
		for(i=0;i<d2;i++)
		{
			k=(s[d+i]=='1')+2*(s[d+i]=='?');
			mka[rr]=mka[rr]*3+k;
		}
	}
	for(i=0;i<1ll<<d;i++)
	{
		for(mk=0;mk<p3[d2];mk++)
		{
			if(dh[mk]==-1)
			{
				dp[mk]=a[i<<d2|pst[mk]];
			}
			else
			{
				dp[mk]=dp[mk-p3[dh[mk]]*2]+dp[mk-p3[dh[mk]]];
			}
		}
		for(rr=0;rr<t;rr++)
		{
			if((i&wgg[rr])==wg[rr])
			{
				sq[rr]+=dp[mka[rr]];
			}
		}
	}
	for(rr=0;rr<t;rr++)
	{
		cout<<sq[rr]<<"\n";
	}
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:56:24: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   56 |    wgg[rr]=wgg[rr]<<1|k<2;
      |                       ~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 1165 ms 23808 KB Output is correct
12 Correct 1363 ms 21308 KB Output is correct
13 Correct 1062 ms 20612 KB Output is correct
14 Correct 1254 ms 20668 KB Output is correct
15 Correct 1227 ms 21692 KB Output is correct
16 Correct 1214 ms 20984 KB Output is correct
17 Correct 1238 ms 20856 KB Output is correct
18 Correct 813 ms 22904 KB Output is correct
19 Correct 836 ms 19704 KB Output is correct
20 Correct 1334 ms 21368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 1165 ms 23808 KB Output is correct
12 Correct 1363 ms 21308 KB Output is correct
13 Correct 1062 ms 20612 KB Output is correct
14 Correct 1254 ms 20668 KB Output is correct
15 Correct 1227 ms 21692 KB Output is correct
16 Correct 1214 ms 20984 KB Output is correct
17 Correct 1238 ms 20856 KB Output is correct
18 Correct 813 ms 22904 KB Output is correct
19 Correct 836 ms 19704 KB Output is correct
20 Correct 1334 ms 21368 KB Output is correct
21 Correct 1275 ms 21692 KB Output is correct
22 Correct 1349 ms 21880 KB Output is correct
23 Correct 1152 ms 20984 KB Output is correct
24 Correct 1268 ms 20728 KB Output is correct
25 Correct 1346 ms 22904 KB Output is correct
26 Correct 1241 ms 21240 KB Output is correct
27 Correct 1260 ms 21240 KB Output is correct
28 Correct 815 ms 23800 KB Output is correct
29 Correct 860 ms 19704 KB Output is correct
30 Correct 1352 ms 21880 KB Output is correct
31 Correct 1137 ms 21752 KB Output is correct
32 Correct 1225 ms 21676 KB Output is correct
33 Correct 951 ms 20600 KB Output is correct
34 Correct 1328 ms 20732 KB Output is correct
35 Correct 1231 ms 21172 KB Output is correct
36 Correct 714 ms 19708 KB Output is correct
37 Correct 1142 ms 21624 KB Output is correct
38 Correct 856 ms 19704 KB Output is correct
39 Correct 1155 ms 20984 KB Output is correct
40 Correct 1245 ms 20640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 265 ms 10268 KB Output is correct
12 Correct 266 ms 10392 KB Output is correct
13 Correct 247 ms 10136 KB Output is correct
14 Correct 265 ms 10392 KB Output is correct
15 Correct 294 ms 10264 KB Output is correct
16 Correct 269 ms 10140 KB Output is correct
17 Correct 253 ms 10176 KB Output is correct
18 Correct 246 ms 10396 KB Output is correct
19 Correct 245 ms 10132 KB Output is correct
20 Correct 263 ms 10264 KB Output is correct
21 Correct 267 ms 10172 KB Output is correct
22 Correct 255 ms 10136 KB Output is correct
23 Correct 255 ms 10264 KB Output is correct
24 Correct 259 ms 10312 KB Output is correct
25 Correct 255 ms 10140 KB Output is correct
26 Correct 239 ms 10132 KB Output is correct
27 Correct 257 ms 10260 KB Output is correct
28 Correct 240 ms 10028 KB Output is correct
29 Correct 248 ms 10268 KB Output is correct
30 Correct 255 ms 10140 KB Output is correct
31 Correct 246 ms 10264 KB Output is correct
32 Correct 253 ms 10264 KB Output is correct
33 Correct 257 ms 10264 KB Output is correct
34 Correct 244 ms 10008 KB Output is correct
35 Correct 265 ms 10136 KB Output is correct
36 Correct 265 ms 10264 KB Output is correct
37 Correct 265 ms 10136 KB Output is correct
38 Correct 265 ms 10136 KB Output is correct
39 Correct 264 ms 10264 KB Output is correct
40 Correct 269 ms 10140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 1165 ms 23808 KB Output is correct
12 Correct 1363 ms 21308 KB Output is correct
13 Correct 1062 ms 20612 KB Output is correct
14 Correct 1254 ms 20668 KB Output is correct
15 Correct 1227 ms 21692 KB Output is correct
16 Correct 1214 ms 20984 KB Output is correct
17 Correct 1238 ms 20856 KB Output is correct
18 Correct 813 ms 22904 KB Output is correct
19 Correct 836 ms 19704 KB Output is correct
20 Correct 1334 ms 21368 KB Output is correct
21 Correct 1275 ms 21692 KB Output is correct
22 Correct 1349 ms 21880 KB Output is correct
23 Correct 1152 ms 20984 KB Output is correct
24 Correct 1268 ms 20728 KB Output is correct
25 Correct 1346 ms 22904 KB Output is correct
26 Correct 1241 ms 21240 KB Output is correct
27 Correct 1260 ms 21240 KB Output is correct
28 Correct 815 ms 23800 KB Output is correct
29 Correct 860 ms 19704 KB Output is correct
30 Correct 1352 ms 21880 KB Output is correct
31 Correct 1137 ms 21752 KB Output is correct
32 Correct 1225 ms 21676 KB Output is correct
33 Correct 951 ms 20600 KB Output is correct
34 Correct 1328 ms 20732 KB Output is correct
35 Correct 1231 ms 21172 KB Output is correct
36 Correct 714 ms 19708 KB Output is correct
37 Correct 1142 ms 21624 KB Output is correct
38 Correct 856 ms 19704 KB Output is correct
39 Correct 1155 ms 20984 KB Output is correct
40 Correct 1245 ms 20640 KB Output is correct
41 Correct 265 ms 10268 KB Output is correct
42 Correct 266 ms 10392 KB Output is correct
43 Correct 247 ms 10136 KB Output is correct
44 Correct 265 ms 10392 KB Output is correct
45 Correct 294 ms 10264 KB Output is correct
46 Correct 269 ms 10140 KB Output is correct
47 Correct 253 ms 10176 KB Output is correct
48 Correct 246 ms 10396 KB Output is correct
49 Correct 245 ms 10132 KB Output is correct
50 Correct 263 ms 10264 KB Output is correct
51 Correct 267 ms 10172 KB Output is correct
52 Correct 255 ms 10136 KB Output is correct
53 Correct 255 ms 10264 KB Output is correct
54 Correct 259 ms 10312 KB Output is correct
55 Correct 255 ms 10140 KB Output is correct
56 Correct 239 ms 10132 KB Output is correct
57 Correct 257 ms 10260 KB Output is correct
58 Correct 240 ms 10028 KB Output is correct
59 Correct 248 ms 10268 KB Output is correct
60 Correct 255 ms 10140 KB Output is correct
61 Correct 246 ms 10264 KB Output is correct
62 Correct 253 ms 10264 KB Output is correct
63 Correct 257 ms 10264 KB Output is correct
64 Correct 244 ms 10008 KB Output is correct
65 Correct 265 ms 10136 KB Output is correct
66 Correct 265 ms 10264 KB Output is correct
67 Correct 265 ms 10136 KB Output is correct
68 Correct 265 ms 10136 KB Output is correct
69 Correct 264 ms 10264 KB Output is correct
70 Correct 269 ms 10140 KB Output is correct
71 Correct 1524 ms 30616 KB Output is correct
72 Correct 1609 ms 30616 KB Output is correct
73 Correct 1484 ms 29080 KB Output is correct
74 Correct 1699 ms 29340 KB Output is correct
75 Execution timed out 2029 ms 31384 KB Time limit exceeded
76 Halted 0 ms 0 KB -