Submission #58954

# Submission time Handle Problem Language Result Execution time Memory
58954 2018-07-19T21:28:55 Z TadijaSebez Snake Escaping (JOI18_snake_escaping) C++11
75 / 100
1595 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[i]=s[i]-'0';
	}
	for(i=0;i<n;i++)
	{
		for(mask=0;mask<(1<<n);mask++)
		{
			if((mask>>i)&1) dp0[mask^(1<<i)]+=dp0[mask];
			else dp1[mask^(1<<i)]+=dp1[mask];
		}
	}
	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);
				int go=((1<<n)-1)^mask^c;
				if((pc[mask]&1)==(pc[a]&1)) ans+=dp0[go];
				else ans-=dp0[go];
				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:27: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 4344 KB Output is correct
2 Correct 7 ms 4580 KB Output is correct
3 Correct 7 ms 4580 KB Output is correct
4 Correct 7 ms 4580 KB Output is correct
5 Correct 7 ms 4580 KB Output is correct
6 Correct 9 ms 4640 KB Output is correct
7 Correct 8 ms 4716 KB Output is correct
8 Correct 8 ms 4716 KB Output is correct
9 Correct 7 ms 4716 KB Output is correct
10 Correct 7 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4344 KB Output is correct
2 Correct 7 ms 4580 KB Output is correct
3 Correct 7 ms 4580 KB Output is correct
4 Correct 7 ms 4580 KB Output is correct
5 Correct 7 ms 4580 KB Output is correct
6 Correct 9 ms 4640 KB Output is correct
7 Correct 8 ms 4716 KB Output is correct
8 Correct 8 ms 4716 KB Output is correct
9 Correct 7 ms 4716 KB Output is correct
10 Correct 7 ms 4716 KB Output is correct
11 Correct 352 ms 8684 KB Output is correct
12 Correct 445 ms 8684 KB Output is correct
13 Correct 369 ms 8684 KB Output is correct
14 Correct 380 ms 8684 KB Output is correct
15 Correct 365 ms 8684 KB Output is correct
16 Correct 417 ms 8684 KB Output is correct
17 Correct 413 ms 8684 KB Output is correct
18 Correct 306 ms 9612 KB Output is correct
19 Correct 349 ms 9612 KB Output is correct
20 Correct 354 ms 9612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4344 KB Output is correct
2 Correct 7 ms 4580 KB Output is correct
3 Correct 7 ms 4580 KB Output is correct
4 Correct 7 ms 4580 KB Output is correct
5 Correct 7 ms 4580 KB Output is correct
6 Correct 9 ms 4640 KB Output is correct
7 Correct 8 ms 4716 KB Output is correct
8 Correct 8 ms 4716 KB Output is correct
9 Correct 7 ms 4716 KB Output is correct
10 Correct 7 ms 4716 KB Output is correct
11 Correct 352 ms 8684 KB Output is correct
12 Correct 445 ms 8684 KB Output is correct
13 Correct 369 ms 8684 KB Output is correct
14 Correct 380 ms 8684 KB Output is correct
15 Correct 365 ms 8684 KB Output is correct
16 Correct 417 ms 8684 KB Output is correct
17 Correct 413 ms 8684 KB Output is correct
18 Correct 306 ms 9612 KB Output is correct
19 Correct 349 ms 9612 KB Output is correct
20 Correct 354 ms 9612 KB Output is correct
21 Correct 440 ms 9612 KB Output is correct
22 Correct 419 ms 9612 KB Output is correct
23 Correct 456 ms 9612 KB Output is correct
24 Correct 470 ms 9612 KB Output is correct
25 Correct 472 ms 9828 KB Output is correct
26 Correct 534 ms 9828 KB Output is correct
27 Correct 461 ms 9828 KB Output is correct
28 Correct 336 ms 10796 KB Output is correct
29 Correct 393 ms 10796 KB Output is correct
30 Correct 478 ms 10796 KB Output is correct
31 Correct 443 ms 10796 KB Output is correct
32 Correct 587 ms 10796 KB Output is correct
33 Correct 432 ms 10796 KB Output is correct
34 Correct 584 ms 10796 KB Output is correct
35 Correct 459 ms 10796 KB Output is correct
36 Correct 306 ms 10796 KB Output is correct
37 Correct 485 ms 10796 KB Output is correct
38 Correct 433 ms 10796 KB Output is correct
39 Correct 553 ms 10796 KB Output is correct
40 Correct 571 ms 10796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4344 KB Output is correct
2 Correct 7 ms 4580 KB Output is correct
3 Correct 7 ms 4580 KB Output is correct
4 Correct 7 ms 4580 KB Output is correct
5 Correct 7 ms 4580 KB Output is correct
6 Correct 9 ms 4640 KB Output is correct
7 Correct 8 ms 4716 KB Output is correct
8 Correct 8 ms 4716 KB Output is correct
9 Correct 7 ms 4716 KB Output is correct
10 Correct 7 ms 4716 KB Output is correct
11 Correct 92 ms 14112 KB Output is correct
12 Correct 89 ms 14236 KB Output is correct
13 Correct 113 ms 14276 KB Output is correct
14 Correct 192 ms 14276 KB Output is correct
15 Correct 124 ms 14276 KB Output is correct
16 Correct 134 ms 14276 KB Output is correct
17 Correct 160 ms 14276 KB Output is correct
18 Correct 108 ms 14276 KB Output is correct
19 Correct 103 ms 14276 KB Output is correct
20 Correct 94 ms 14276 KB Output is correct
21 Correct 126 ms 14276 KB Output is correct
22 Correct 141 ms 14276 KB Output is correct
23 Correct 115 ms 14276 KB Output is correct
24 Correct 134 ms 14276 KB Output is correct
25 Correct 125 ms 14276 KB Output is correct
26 Correct 77 ms 14276 KB Output is correct
27 Correct 102 ms 14276 KB Output is correct
28 Correct 102 ms 14276 KB Output is correct
29 Correct 112 ms 14276 KB Output is correct
30 Correct 112 ms 14276 KB Output is correct
31 Correct 104 ms 14276 KB Output is correct
32 Correct 183 ms 14276 KB Output is correct
33 Correct 122 ms 14276 KB Output is correct
34 Correct 76 ms 14276 KB Output is correct
35 Correct 118 ms 14276 KB Output is correct
36 Correct 116 ms 14276 KB Output is correct
37 Correct 114 ms 14276 KB Output is correct
38 Correct 115 ms 14276 KB Output is correct
39 Correct 128 ms 14276 KB Output is correct
40 Correct 114 ms 14276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4344 KB Output is correct
2 Correct 7 ms 4580 KB Output is correct
3 Correct 7 ms 4580 KB Output is correct
4 Correct 7 ms 4580 KB Output is correct
5 Correct 7 ms 4580 KB Output is correct
6 Correct 9 ms 4640 KB Output is correct
7 Correct 8 ms 4716 KB Output is correct
8 Correct 8 ms 4716 KB Output is correct
9 Correct 7 ms 4716 KB Output is correct
10 Correct 7 ms 4716 KB Output is correct
11 Correct 352 ms 8684 KB Output is correct
12 Correct 445 ms 8684 KB Output is correct
13 Correct 369 ms 8684 KB Output is correct
14 Correct 380 ms 8684 KB Output is correct
15 Correct 365 ms 8684 KB Output is correct
16 Correct 417 ms 8684 KB Output is correct
17 Correct 413 ms 8684 KB Output is correct
18 Correct 306 ms 9612 KB Output is correct
19 Correct 349 ms 9612 KB Output is correct
20 Correct 354 ms 9612 KB Output is correct
21 Correct 440 ms 9612 KB Output is correct
22 Correct 419 ms 9612 KB Output is correct
23 Correct 456 ms 9612 KB Output is correct
24 Correct 470 ms 9612 KB Output is correct
25 Correct 472 ms 9828 KB Output is correct
26 Correct 534 ms 9828 KB Output is correct
27 Correct 461 ms 9828 KB Output is correct
28 Correct 336 ms 10796 KB Output is correct
29 Correct 393 ms 10796 KB Output is correct
30 Correct 478 ms 10796 KB Output is correct
31 Correct 443 ms 10796 KB Output is correct
32 Correct 587 ms 10796 KB Output is correct
33 Correct 432 ms 10796 KB Output is correct
34 Correct 584 ms 10796 KB Output is correct
35 Correct 459 ms 10796 KB Output is correct
36 Correct 306 ms 10796 KB Output is correct
37 Correct 485 ms 10796 KB Output is correct
38 Correct 433 ms 10796 KB Output is correct
39 Correct 553 ms 10796 KB Output is correct
40 Correct 571 ms 10796 KB Output is correct
41 Correct 92 ms 14112 KB Output is correct
42 Correct 89 ms 14236 KB Output is correct
43 Correct 113 ms 14276 KB Output is correct
44 Correct 192 ms 14276 KB Output is correct
45 Correct 124 ms 14276 KB Output is correct
46 Correct 134 ms 14276 KB Output is correct
47 Correct 160 ms 14276 KB Output is correct
48 Correct 108 ms 14276 KB Output is correct
49 Correct 103 ms 14276 KB Output is correct
50 Correct 94 ms 14276 KB Output is correct
51 Correct 126 ms 14276 KB Output is correct
52 Correct 141 ms 14276 KB Output is correct
53 Correct 115 ms 14276 KB Output is correct
54 Correct 134 ms 14276 KB Output is correct
55 Correct 125 ms 14276 KB Output is correct
56 Correct 77 ms 14276 KB Output is correct
57 Correct 102 ms 14276 KB Output is correct
58 Correct 102 ms 14276 KB Output is correct
59 Correct 112 ms 14276 KB Output is correct
60 Correct 112 ms 14276 KB Output is correct
61 Correct 104 ms 14276 KB Output is correct
62 Correct 183 ms 14276 KB Output is correct
63 Correct 122 ms 14276 KB Output is correct
64 Correct 76 ms 14276 KB Output is correct
65 Correct 118 ms 14276 KB Output is correct
66 Correct 116 ms 14276 KB Output is correct
67 Correct 114 ms 14276 KB Output is correct
68 Correct 115 ms 14276 KB Output is correct
69 Correct 128 ms 14276 KB Output is correct
70 Correct 114 ms 14276 KB Output is correct
71 Correct 759 ms 18940 KB Output is correct
72 Correct 751 ms 40644 KB Output is correct
73 Correct 1061 ms 60824 KB Output is correct
74 Runtime error 1595 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.
75 Halted 0 ms 0 KB -