Submission #58956

# Submission time Handle Problem Language Result Execution time Memory
58956 2018-07-19T21:31:29 Z TadijaSebez Snake Escaping (JOI18_snake_escaping) C++11
75 / 100
1413 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 7 ms 4472 KB Output is correct
2 Correct 6 ms 4472 KB Output is correct
3 Correct 6 ms 4508 KB Output is correct
4 Correct 6 ms 4508 KB Output is correct
5 Correct 6 ms 4524 KB Output is correct
6 Correct 7 ms 4524 KB Output is correct
7 Correct 6 ms 4576 KB Output is correct
8 Correct 6 ms 4576 KB Output is correct
9 Correct 7 ms 4576 KB Output is correct
10 Correct 6 ms 4624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4472 KB Output is correct
2 Correct 6 ms 4472 KB Output is correct
3 Correct 6 ms 4508 KB Output is correct
4 Correct 6 ms 4508 KB Output is correct
5 Correct 6 ms 4524 KB Output is correct
6 Correct 7 ms 4524 KB Output is correct
7 Correct 6 ms 4576 KB Output is correct
8 Correct 6 ms 4576 KB Output is correct
9 Correct 7 ms 4576 KB Output is correct
10 Correct 6 ms 4624 KB Output is correct
11 Correct 298 ms 8620 KB Output is correct
12 Correct 310 ms 8620 KB Output is correct
13 Correct 334 ms 8620 KB Output is correct
14 Correct 343 ms 8620 KB Output is correct
15 Correct 315 ms 8664 KB Output is correct
16 Correct 357 ms 8664 KB Output is correct
17 Correct 409 ms 8664 KB Output is correct
18 Correct 267 ms 9588 KB Output is correct
19 Correct 349 ms 9588 KB Output is correct
20 Correct 330 ms 9588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4472 KB Output is correct
2 Correct 6 ms 4472 KB Output is correct
3 Correct 6 ms 4508 KB Output is correct
4 Correct 6 ms 4508 KB Output is correct
5 Correct 6 ms 4524 KB Output is correct
6 Correct 7 ms 4524 KB Output is correct
7 Correct 6 ms 4576 KB Output is correct
8 Correct 6 ms 4576 KB Output is correct
9 Correct 7 ms 4576 KB Output is correct
10 Correct 6 ms 4624 KB Output is correct
11 Correct 298 ms 8620 KB Output is correct
12 Correct 310 ms 8620 KB Output is correct
13 Correct 334 ms 8620 KB Output is correct
14 Correct 343 ms 8620 KB Output is correct
15 Correct 315 ms 8664 KB Output is correct
16 Correct 357 ms 8664 KB Output is correct
17 Correct 409 ms 8664 KB Output is correct
18 Correct 267 ms 9588 KB Output is correct
19 Correct 349 ms 9588 KB Output is correct
20 Correct 330 ms 9588 KB Output is correct
21 Correct 356 ms 9588 KB Output is correct
22 Correct 385 ms 9588 KB Output is correct
23 Correct 456 ms 9588 KB Output is correct
24 Correct 512 ms 9588 KB Output is correct
25 Correct 396 ms 9784 KB Output is correct
26 Correct 468 ms 9784 KB Output is correct
27 Correct 485 ms 9784 KB Output is correct
28 Correct 268 ms 10712 KB Output is correct
29 Correct 336 ms 10712 KB Output is correct
30 Correct 362 ms 10712 KB Output is correct
31 Correct 420 ms 10712 KB Output is correct
32 Correct 462 ms 10712 KB Output is correct
33 Correct 356 ms 10712 KB Output is correct
34 Correct 431 ms 10712 KB Output is correct
35 Correct 429 ms 10712 KB Output is correct
36 Correct 293 ms 10712 KB Output is correct
37 Correct 360 ms 10712 KB Output is correct
38 Correct 406 ms 10712 KB Output is correct
39 Correct 443 ms 10712 KB Output is correct
40 Correct 475 ms 10712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4472 KB Output is correct
2 Correct 6 ms 4472 KB Output is correct
3 Correct 6 ms 4508 KB Output is correct
4 Correct 6 ms 4508 KB Output is correct
5 Correct 6 ms 4524 KB Output is correct
6 Correct 7 ms 4524 KB Output is correct
7 Correct 6 ms 4576 KB Output is correct
8 Correct 6 ms 4576 KB Output is correct
9 Correct 7 ms 4576 KB Output is correct
10 Correct 6 ms 4624 KB Output is correct
11 Correct 78 ms 14124 KB Output is correct
12 Correct 83 ms 14224 KB Output is correct
13 Correct 96 ms 14224 KB Output is correct
14 Correct 117 ms 14224 KB Output is correct
15 Correct 85 ms 14252 KB Output is correct
16 Correct 131 ms 14252 KB Output is correct
17 Correct 110 ms 14252 KB Output is correct
18 Correct 83 ms 14380 KB Output is correct
19 Correct 80 ms 14380 KB Output is correct
20 Correct 90 ms 14380 KB Output is correct
21 Correct 88 ms 14380 KB Output is correct
22 Correct 147 ms 14380 KB Output is correct
23 Correct 80 ms 14380 KB Output is correct
24 Correct 104 ms 14380 KB Output is correct
25 Correct 107 ms 14380 KB Output is correct
26 Correct 67 ms 14380 KB Output is correct
27 Correct 82 ms 14380 KB Output is correct
28 Correct 80 ms 14380 KB Output is correct
29 Correct 108 ms 14380 KB Output is correct
30 Correct 97 ms 14380 KB Output is correct
31 Correct 94 ms 14380 KB Output is correct
32 Correct 120 ms 14380 KB Output is correct
33 Correct 97 ms 14380 KB Output is correct
34 Correct 79 ms 14380 KB Output is correct
35 Correct 109 ms 14380 KB Output is correct
36 Correct 91 ms 14380 KB Output is correct
37 Correct 90 ms 14380 KB Output is correct
38 Correct 102 ms 14380 KB Output is correct
39 Correct 93 ms 14380 KB Output is correct
40 Correct 114 ms 14380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4472 KB Output is correct
2 Correct 6 ms 4472 KB Output is correct
3 Correct 6 ms 4508 KB Output is correct
4 Correct 6 ms 4508 KB Output is correct
5 Correct 6 ms 4524 KB Output is correct
6 Correct 7 ms 4524 KB Output is correct
7 Correct 6 ms 4576 KB Output is correct
8 Correct 6 ms 4576 KB Output is correct
9 Correct 7 ms 4576 KB Output is correct
10 Correct 6 ms 4624 KB Output is correct
11 Correct 298 ms 8620 KB Output is correct
12 Correct 310 ms 8620 KB Output is correct
13 Correct 334 ms 8620 KB Output is correct
14 Correct 343 ms 8620 KB Output is correct
15 Correct 315 ms 8664 KB Output is correct
16 Correct 357 ms 8664 KB Output is correct
17 Correct 409 ms 8664 KB Output is correct
18 Correct 267 ms 9588 KB Output is correct
19 Correct 349 ms 9588 KB Output is correct
20 Correct 330 ms 9588 KB Output is correct
21 Correct 356 ms 9588 KB Output is correct
22 Correct 385 ms 9588 KB Output is correct
23 Correct 456 ms 9588 KB Output is correct
24 Correct 512 ms 9588 KB Output is correct
25 Correct 396 ms 9784 KB Output is correct
26 Correct 468 ms 9784 KB Output is correct
27 Correct 485 ms 9784 KB Output is correct
28 Correct 268 ms 10712 KB Output is correct
29 Correct 336 ms 10712 KB Output is correct
30 Correct 362 ms 10712 KB Output is correct
31 Correct 420 ms 10712 KB Output is correct
32 Correct 462 ms 10712 KB Output is correct
33 Correct 356 ms 10712 KB Output is correct
34 Correct 431 ms 10712 KB Output is correct
35 Correct 429 ms 10712 KB Output is correct
36 Correct 293 ms 10712 KB Output is correct
37 Correct 360 ms 10712 KB Output is correct
38 Correct 406 ms 10712 KB Output is correct
39 Correct 443 ms 10712 KB Output is correct
40 Correct 475 ms 10712 KB Output is correct
41 Correct 78 ms 14124 KB Output is correct
42 Correct 83 ms 14224 KB Output is correct
43 Correct 96 ms 14224 KB Output is correct
44 Correct 117 ms 14224 KB Output is correct
45 Correct 85 ms 14252 KB Output is correct
46 Correct 131 ms 14252 KB Output is correct
47 Correct 110 ms 14252 KB Output is correct
48 Correct 83 ms 14380 KB Output is correct
49 Correct 80 ms 14380 KB Output is correct
50 Correct 90 ms 14380 KB Output is correct
51 Correct 88 ms 14380 KB Output is correct
52 Correct 147 ms 14380 KB Output is correct
53 Correct 80 ms 14380 KB Output is correct
54 Correct 104 ms 14380 KB Output is correct
55 Correct 107 ms 14380 KB Output is correct
56 Correct 67 ms 14380 KB Output is correct
57 Correct 82 ms 14380 KB Output is correct
58 Correct 80 ms 14380 KB Output is correct
59 Correct 108 ms 14380 KB Output is correct
60 Correct 97 ms 14380 KB Output is correct
61 Correct 94 ms 14380 KB Output is correct
62 Correct 120 ms 14380 KB Output is correct
63 Correct 97 ms 14380 KB Output is correct
64 Correct 79 ms 14380 KB Output is correct
65 Correct 109 ms 14380 KB Output is correct
66 Correct 91 ms 14380 KB Output is correct
67 Correct 90 ms 14380 KB Output is correct
68 Correct 102 ms 14380 KB Output is correct
69 Correct 93 ms 14380 KB Output is correct
70 Correct 114 ms 14380 KB Output is correct
71 Correct 703 ms 19044 KB Output is correct
72 Correct 744 ms 35396 KB Output is correct
73 Correct 987 ms 35396 KB Output is correct
74 Correct 1123 ms 35396 KB Output is correct
75 Correct 674 ms 58148 KB Output is correct
76 Runtime error 1413 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.
77 Halted 0 ms 0 KB -