Submission #58957

# Submission time Handle Problem Language Result Execution time Memory
58957 2018-07-19T21:32:17 Z TadijaSebez Snake Escaping (JOI18_snake_escaping) C++11
75 / 100
1589 ms 66560 KB
#include <stdio.h>
const int N=1<<20;
int dp0[N],dp1[N],pc[N];
char s[N],t[20];
int min(int a, int b){ return a>b?b:a;}
int abs(int x){ return x>0?x:-x;}
int main()
{
	int n,q,i,mask;
	for(i=1;i<N;i++) pc[i]=pc[i-(i&-i)]+1;
	scanf("%i %i",&n,&q);
	scanf("%s",s);
	for(i=0;i<(1<<n);i++)
	{
		dp1[i]=dp0[((1<<n)-1)^i]=s[i]-'0';
	}
	for(i=0;i<n;i++)
	{
		for(mask=0;mask<(1<<n);mask++)
		{
			if((mask>>i)&1)
			{
				dp1[mask]+=dp1[mask^(1<<i)];
				dp0[mask]+=dp0[mask^(1<<i)];
			}
		}
	}
	while(q--)
	{
		scanf("%s",t);
		int a=0,b=0,c=0;
		for(i=0;i<n;i++)
		{
			if(t[n-i-1]=='0') a+=1<<i;
			else if(t[n-i-1]=='1') b+=1<<i;
			else c+=1<<i;
		}
		int ans=0;
		if(pc[a]<=min(pc[b],pc[c]))
		{
			for(mask=a;;mask=(mask-1)&a)
			{
				//printf("a:%i %i\n",a,mask);
				if((pc[mask]&1)==(pc[a]&1)) ans+=dp0[mask|c];
				else ans-=dp0[mask|c];
				if(!mask) break;
			}
		}
		else if(pc[b]<=min(pc[a],pc[c]))
		{
			for(mask=b;;mask=(mask-1)&b)
			{
				//printf("b:%i %i\n",b,mask);
				if((pc[mask]&1)==(pc[b]&1)) ans+=dp1[mask|c];
				else ans-=dp1[mask|c];
				if(!mask) break;
			}
		}
		else
		{
			for(mask=c;;mask=(mask-1)&c)
			{
				//printf("c:%i %i\n",c,mask);
				ans+=s[mask|b]-'0';
				if(!mask) break;
			}
		}
		printf("%i\n",abs(ans));
	}
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s);
  ~~~~~^~~~~~~~
snake_escaping.cpp:30:8: 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 8 ms 4436 KB Output is correct
2 Correct 8 ms 4552 KB Output is correct
3 Correct 7 ms 4576 KB Output is correct
4 Correct 6 ms 4576 KB Output is correct
5 Correct 6 ms 4576 KB Output is correct
6 Correct 9 ms 4696 KB Output is correct
7 Correct 8 ms 4696 KB Output is correct
8 Correct 6 ms 4696 KB Output is correct
9 Correct 7 ms 4696 KB Output is correct
10 Correct 6 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4436 KB Output is correct
2 Correct 8 ms 4552 KB Output is correct
3 Correct 7 ms 4576 KB Output is correct
4 Correct 6 ms 4576 KB Output is correct
5 Correct 6 ms 4576 KB Output is correct
6 Correct 9 ms 4696 KB Output is correct
7 Correct 8 ms 4696 KB Output is correct
8 Correct 6 ms 4696 KB Output is correct
9 Correct 7 ms 4696 KB Output is correct
10 Correct 6 ms 4696 KB Output is correct
11 Correct 343 ms 8540 KB Output is correct
12 Correct 326 ms 8540 KB Output is correct
13 Correct 365 ms 8540 KB Output is correct
14 Correct 350 ms 8540 KB Output is correct
15 Correct 365 ms 8576 KB Output is correct
16 Correct 411 ms 8576 KB Output is correct
17 Correct 402 ms 8576 KB Output is correct
18 Correct 252 ms 9572 KB Output is correct
19 Correct 298 ms 9572 KB Output is correct
20 Correct 322 ms 9572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4436 KB Output is correct
2 Correct 8 ms 4552 KB Output is correct
3 Correct 7 ms 4576 KB Output is correct
4 Correct 6 ms 4576 KB Output is correct
5 Correct 6 ms 4576 KB Output is correct
6 Correct 9 ms 4696 KB Output is correct
7 Correct 8 ms 4696 KB Output is correct
8 Correct 6 ms 4696 KB Output is correct
9 Correct 7 ms 4696 KB Output is correct
10 Correct 6 ms 4696 KB Output is correct
11 Correct 343 ms 8540 KB Output is correct
12 Correct 326 ms 8540 KB Output is correct
13 Correct 365 ms 8540 KB Output is correct
14 Correct 350 ms 8540 KB Output is correct
15 Correct 365 ms 8576 KB Output is correct
16 Correct 411 ms 8576 KB Output is correct
17 Correct 402 ms 8576 KB Output is correct
18 Correct 252 ms 9572 KB Output is correct
19 Correct 298 ms 9572 KB Output is correct
20 Correct 322 ms 9572 KB Output is correct
21 Correct 359 ms 9572 KB Output is correct
22 Correct 441 ms 9572 KB Output is correct
23 Correct 465 ms 9572 KB Output is correct
24 Correct 455 ms 9572 KB Output is correct
25 Correct 383 ms 9772 KB Output is correct
26 Correct 460 ms 9772 KB Output is correct
27 Correct 423 ms 9772 KB Output is correct
28 Correct 290 ms 10796 KB Output is correct
29 Correct 369 ms 10796 KB Output is correct
30 Correct 381 ms 10796 KB Output is correct
31 Correct 410 ms 10796 KB Output is correct
32 Correct 443 ms 10796 KB Output is correct
33 Correct 380 ms 10796 KB Output is correct
34 Correct 419 ms 10796 KB Output is correct
35 Correct 403 ms 10796 KB Output is correct
36 Correct 262 ms 10796 KB Output is correct
37 Correct 436 ms 10796 KB Output is correct
38 Correct 373 ms 10796 KB Output is correct
39 Correct 464 ms 10796 KB Output is correct
40 Correct 432 ms 10796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4436 KB Output is correct
2 Correct 8 ms 4552 KB Output is correct
3 Correct 7 ms 4576 KB Output is correct
4 Correct 6 ms 4576 KB Output is correct
5 Correct 6 ms 4576 KB Output is correct
6 Correct 9 ms 4696 KB Output is correct
7 Correct 8 ms 4696 KB Output is correct
8 Correct 6 ms 4696 KB Output is correct
9 Correct 7 ms 4696 KB Output is correct
10 Correct 6 ms 4696 KB Output is correct
11 Correct 82 ms 14124 KB Output is correct
12 Correct 78 ms 14132 KB Output is correct
13 Correct 92 ms 14132 KB Output is correct
14 Correct 118 ms 14132 KB Output is correct
15 Correct 83 ms 14380 KB Output is correct
16 Correct 120 ms 14380 KB Output is correct
17 Correct 113 ms 14380 KB Output is correct
18 Correct 70 ms 14380 KB Output is correct
19 Correct 87 ms 14380 KB Output is correct
20 Correct 83 ms 14380 KB Output is correct
21 Correct 95 ms 14380 KB Output is correct
22 Correct 131 ms 14380 KB Output is correct
23 Correct 99 ms 14380 KB Output is correct
24 Correct 117 ms 14380 KB Output is correct
25 Correct 112 ms 14380 KB Output is correct
26 Correct 83 ms 14380 KB Output is correct
27 Correct 87 ms 14380 KB Output is correct
28 Correct 78 ms 14380 KB Output is correct
29 Correct 97 ms 14380 KB Output is correct
30 Correct 92 ms 14380 KB Output is correct
31 Correct 80 ms 14380 KB Output is correct
32 Correct 120 ms 14380 KB Output is correct
33 Correct 117 ms 14380 KB Output is correct
34 Correct 65 ms 14380 KB Output is correct
35 Correct 98 ms 14380 KB Output is correct
36 Correct 93 ms 14380 KB Output is correct
37 Correct 102 ms 14380 KB Output is correct
38 Correct 107 ms 14380 KB Output is correct
39 Correct 93 ms 14380 KB Output is correct
40 Correct 130 ms 14380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4436 KB Output is correct
2 Correct 8 ms 4552 KB Output is correct
3 Correct 7 ms 4576 KB Output is correct
4 Correct 6 ms 4576 KB Output is correct
5 Correct 6 ms 4576 KB Output is correct
6 Correct 9 ms 4696 KB Output is correct
7 Correct 8 ms 4696 KB Output is correct
8 Correct 6 ms 4696 KB Output is correct
9 Correct 7 ms 4696 KB Output is correct
10 Correct 6 ms 4696 KB Output is correct
11 Correct 343 ms 8540 KB Output is correct
12 Correct 326 ms 8540 KB Output is correct
13 Correct 365 ms 8540 KB Output is correct
14 Correct 350 ms 8540 KB Output is correct
15 Correct 365 ms 8576 KB Output is correct
16 Correct 411 ms 8576 KB Output is correct
17 Correct 402 ms 8576 KB Output is correct
18 Correct 252 ms 9572 KB Output is correct
19 Correct 298 ms 9572 KB Output is correct
20 Correct 322 ms 9572 KB Output is correct
21 Correct 359 ms 9572 KB Output is correct
22 Correct 441 ms 9572 KB Output is correct
23 Correct 465 ms 9572 KB Output is correct
24 Correct 455 ms 9572 KB Output is correct
25 Correct 383 ms 9772 KB Output is correct
26 Correct 460 ms 9772 KB Output is correct
27 Correct 423 ms 9772 KB Output is correct
28 Correct 290 ms 10796 KB Output is correct
29 Correct 369 ms 10796 KB Output is correct
30 Correct 381 ms 10796 KB Output is correct
31 Correct 410 ms 10796 KB Output is correct
32 Correct 443 ms 10796 KB Output is correct
33 Correct 380 ms 10796 KB Output is correct
34 Correct 419 ms 10796 KB Output is correct
35 Correct 403 ms 10796 KB Output is correct
36 Correct 262 ms 10796 KB Output is correct
37 Correct 436 ms 10796 KB Output is correct
38 Correct 373 ms 10796 KB Output is correct
39 Correct 464 ms 10796 KB Output is correct
40 Correct 432 ms 10796 KB Output is correct
41 Correct 82 ms 14124 KB Output is correct
42 Correct 78 ms 14132 KB Output is correct
43 Correct 92 ms 14132 KB Output is correct
44 Correct 118 ms 14132 KB Output is correct
45 Correct 83 ms 14380 KB Output is correct
46 Correct 120 ms 14380 KB Output is correct
47 Correct 113 ms 14380 KB Output is correct
48 Correct 70 ms 14380 KB Output is correct
49 Correct 87 ms 14380 KB Output is correct
50 Correct 83 ms 14380 KB Output is correct
51 Correct 95 ms 14380 KB Output is correct
52 Correct 131 ms 14380 KB Output is correct
53 Correct 99 ms 14380 KB Output is correct
54 Correct 117 ms 14380 KB Output is correct
55 Correct 112 ms 14380 KB Output is correct
56 Correct 83 ms 14380 KB Output is correct
57 Correct 87 ms 14380 KB Output is correct
58 Correct 78 ms 14380 KB Output is correct
59 Correct 97 ms 14380 KB Output is correct
60 Correct 92 ms 14380 KB Output is correct
61 Correct 80 ms 14380 KB Output is correct
62 Correct 120 ms 14380 KB Output is correct
63 Correct 117 ms 14380 KB Output is correct
64 Correct 65 ms 14380 KB Output is correct
65 Correct 98 ms 14380 KB Output is correct
66 Correct 93 ms 14380 KB Output is correct
67 Correct 102 ms 14380 KB Output is correct
68 Correct 107 ms 14380 KB Output is correct
69 Correct 93 ms 14380 KB Output is correct
70 Correct 130 ms 14380 KB Output is correct
71 Correct 656 ms 18896 KB Output is correct
72 Correct 668 ms 19204 KB Output is correct
73 Correct 921 ms 19204 KB Output is correct
74 Correct 1330 ms 19204 KB Output is correct
75 Correct 729 ms 41744 KB Output is correct
76 Correct 1589 ms 41744 KB Output is correct
77 Correct 1270 ms 61572 KB Output is correct
78 Runtime error 438 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
79 Halted 0 ms 0 KB -