Submission #41088

# Submission time Handle Problem Language Result Execution time Memory
41088 2018-02-12T15:09:13 Z kriii Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
865 ms 21960 KB
#include <stdio.h>

int L,Q;
char sc[1<<20+2]; int bc[1<<20];
int Z[1<<20],O[1<<20];

void go(int l, int r)
{
	if (l+1 == r) return;

	int m = (l + r) / 2;
	go(l,m);
	go(m,r);
	for (int i=l;i<m;i++){
		Z[i-l+m] += Z[i];
		O[i] += O[i-l+m];
	}
}

int main()
{
	scanf ("%d %d",&L,&Q);
	scanf ("%s",sc);

	for (int i=0;i<(1<<L);i++){
		if (i) bc[i] = bc[i-(i&(-i))] + 1;
		Z[i] = O[i] = sc[i] - '0';
	}
	go(0,(1<<L));

	while (Q--){
		char q[22]; scanf ("%s",q);
		int z = 0, o = 0, f = 0;
		for (int i=0;i<L;i++){
			if (q[i] == '0') z |= 1 << (L - i - 1);
			if (q[i] == '1') o |= 1 << (L - i - 1);
			if (q[i] == '?') f |= 1 << (L - i - 1);
		}
		int ans = 0;
		if (bc[f] <= 7){
			for (int x=f;;x=(x-1)&f){
				ans += sc[x|o] - '0';
				if (!x) break;
			}
		}
		else if (bc[o] <= 7){
			for (int x=o;;x=(x-1)&o){
				int b = f + x;
				if (bc[o] % 2 != bc[x] % 2) ans -= Z[b];
				else ans += Z[b];
				if (!x) break;
			}
		}
		else{
			for (int x=z;;x=(x-1)&z){
				int b = o + z - x;
				if (bc[z] % 2 != bc[x] % 2) ans -= O[b];
				else ans += O[b];
				if (!x) break;
			}
		}
		printf ("%d\n",ans);
	}
	return 0;
}

Compilation message

snake_escaping.cpp:4:10: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
 char sc[1<<20+2]; int bc[1<<20];
          ^
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:22:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d %d",&L,&Q);
                       ^
snake_escaping.cpp:23:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%s",sc);
                 ^
snake_escaping.cpp:32:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   char q[22]; scanf ("%s",q);
                             ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 552 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 552 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 330 ms 4556 KB Output is correct
12 Correct 349 ms 4556 KB Output is correct
13 Correct 317 ms 4556 KB Output is correct
14 Correct 299 ms 4556 KB Output is correct
15 Correct 379 ms 4556 KB Output is correct
16 Correct 333 ms 4556 KB Output is correct
17 Correct 352 ms 4556 KB Output is correct
18 Correct 239 ms 5496 KB Output is correct
19 Correct 257 ms 5496 KB Output is correct
20 Correct 342 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 552 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 330 ms 4556 KB Output is correct
12 Correct 349 ms 4556 KB Output is correct
13 Correct 317 ms 4556 KB Output is correct
14 Correct 299 ms 4556 KB Output is correct
15 Correct 379 ms 4556 KB Output is correct
16 Correct 333 ms 4556 KB Output is correct
17 Correct 352 ms 4556 KB Output is correct
18 Correct 239 ms 5496 KB Output is correct
19 Correct 257 ms 5496 KB Output is correct
20 Correct 342 ms 5496 KB Output is correct
21 Correct 554 ms 5496 KB Output is correct
22 Correct 407 ms 5496 KB Output is correct
23 Correct 391 ms 5496 KB Output is correct
24 Correct 434 ms 5496 KB Output is correct
25 Correct 364 ms 5616 KB Output is correct
26 Correct 435 ms 5616 KB Output is correct
27 Correct 445 ms 5616 KB Output is correct
28 Correct 257 ms 6684 KB Output is correct
29 Correct 315 ms 6684 KB Output is correct
30 Correct 443 ms 6684 KB Output is correct
31 Correct 490 ms 6684 KB Output is correct
32 Correct 417 ms 6684 KB Output is correct
33 Correct 346 ms 6684 KB Output is correct
34 Correct 377 ms 6684 KB Output is correct
35 Correct 405 ms 6684 KB Output is correct
36 Correct 268 ms 6684 KB Output is correct
37 Correct 420 ms 6684 KB Output is correct
38 Correct 343 ms 6684 KB Output is correct
39 Correct 417 ms 6684 KB Output is correct
40 Correct 421 ms 6684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 552 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 71 ms 14224 KB Output is correct
12 Correct 65 ms 14228 KB Output is correct
13 Correct 73 ms 14228 KB Output is correct
14 Correct 74 ms 14228 KB Output is correct
15 Correct 64 ms 14232 KB Output is correct
16 Correct 74 ms 14232 KB Output is correct
17 Correct 110 ms 14232 KB Output is correct
18 Correct 58 ms 14364 KB Output is correct
19 Correct 64 ms 14364 KB Output is correct
20 Correct 68 ms 14364 KB Output is correct
21 Correct 71 ms 14364 KB Output is correct
22 Correct 74 ms 14364 KB Output is correct
23 Correct 66 ms 14364 KB Output is correct
24 Correct 70 ms 14364 KB Output is correct
25 Correct 74 ms 14364 KB Output is correct
26 Correct 54 ms 14364 KB Output is correct
27 Correct 71 ms 14364 KB Output is correct
28 Correct 72 ms 14364 KB Output is correct
29 Correct 75 ms 14364 KB Output is correct
30 Correct 68 ms 14364 KB Output is correct
31 Correct 60 ms 14364 KB Output is correct
32 Correct 122 ms 14364 KB Output is correct
33 Correct 80 ms 14364 KB Output is correct
34 Correct 51 ms 14364 KB Output is correct
35 Correct 73 ms 14364 KB Output is correct
36 Correct 68 ms 14364 KB Output is correct
37 Correct 69 ms 14364 KB Output is correct
38 Correct 74 ms 14364 KB Output is correct
39 Correct 69 ms 14364 KB Output is correct
40 Correct 78 ms 14364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 552 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 330 ms 4556 KB Output is correct
12 Correct 349 ms 4556 KB Output is correct
13 Correct 317 ms 4556 KB Output is correct
14 Correct 299 ms 4556 KB Output is correct
15 Correct 379 ms 4556 KB Output is correct
16 Correct 333 ms 4556 KB Output is correct
17 Correct 352 ms 4556 KB Output is correct
18 Correct 239 ms 5496 KB Output is correct
19 Correct 257 ms 5496 KB Output is correct
20 Correct 342 ms 5496 KB Output is correct
21 Correct 554 ms 5496 KB Output is correct
22 Correct 407 ms 5496 KB Output is correct
23 Correct 391 ms 5496 KB Output is correct
24 Correct 434 ms 5496 KB Output is correct
25 Correct 364 ms 5616 KB Output is correct
26 Correct 435 ms 5616 KB Output is correct
27 Correct 445 ms 5616 KB Output is correct
28 Correct 257 ms 6684 KB Output is correct
29 Correct 315 ms 6684 KB Output is correct
30 Correct 443 ms 6684 KB Output is correct
31 Correct 490 ms 6684 KB Output is correct
32 Correct 417 ms 6684 KB Output is correct
33 Correct 346 ms 6684 KB Output is correct
34 Correct 377 ms 6684 KB Output is correct
35 Correct 405 ms 6684 KB Output is correct
36 Correct 268 ms 6684 KB Output is correct
37 Correct 420 ms 6684 KB Output is correct
38 Correct 343 ms 6684 KB Output is correct
39 Correct 417 ms 6684 KB Output is correct
40 Correct 421 ms 6684 KB Output is correct
41 Correct 71 ms 14224 KB Output is correct
42 Correct 65 ms 14228 KB Output is correct
43 Correct 73 ms 14228 KB Output is correct
44 Correct 74 ms 14228 KB Output is correct
45 Correct 64 ms 14232 KB Output is correct
46 Correct 74 ms 14232 KB Output is correct
47 Correct 110 ms 14232 KB Output is correct
48 Correct 58 ms 14364 KB Output is correct
49 Correct 64 ms 14364 KB Output is correct
50 Correct 68 ms 14364 KB Output is correct
51 Correct 71 ms 14364 KB Output is correct
52 Correct 74 ms 14364 KB Output is correct
53 Correct 66 ms 14364 KB Output is correct
54 Correct 70 ms 14364 KB Output is correct
55 Correct 74 ms 14364 KB Output is correct
56 Correct 54 ms 14364 KB Output is correct
57 Correct 71 ms 14364 KB Output is correct
58 Correct 72 ms 14364 KB Output is correct
59 Correct 75 ms 14364 KB Output is correct
60 Correct 68 ms 14364 KB Output is correct
61 Correct 60 ms 14364 KB Output is correct
62 Correct 122 ms 14364 KB Output is correct
63 Correct 80 ms 14364 KB Output is correct
64 Correct 51 ms 14364 KB Output is correct
65 Correct 73 ms 14364 KB Output is correct
66 Correct 68 ms 14364 KB Output is correct
67 Correct 69 ms 14364 KB Output is correct
68 Correct 74 ms 14364 KB Output is correct
69 Correct 69 ms 14364 KB Output is correct
70 Correct 78 ms 14364 KB Output is correct
71 Correct 587 ms 18944 KB Output is correct
72 Correct 656 ms 19156 KB Output is correct
73 Correct 658 ms 19156 KB Output is correct
74 Correct 824 ms 19156 KB Output is correct
75 Correct 614 ms 19920 KB Output is correct
76 Correct 864 ms 19920 KB Output is correct
77 Correct 825 ms 19920 KB Output is correct
78 Correct 339 ms 21960 KB Output is correct
79 Correct 447 ms 21960 KB Output is correct
80 Correct 709 ms 21960 KB Output is correct
81 Correct 756 ms 21960 KB Output is correct
82 Correct 815 ms 21960 KB Output is correct
83 Correct 512 ms 21960 KB Output is correct
84 Correct 654 ms 21960 KB Output is correct
85 Correct 821 ms 21960 KB Output is correct
86 Correct 346 ms 21960 KB Output is correct
87 Correct 536 ms 21960 KB Output is correct
88 Correct 468 ms 21960 KB Output is correct
89 Correct 606 ms 21960 KB Output is correct
90 Correct 742 ms 21960 KB Output is correct
91 Correct 517 ms 21960 KB Output is correct
92 Correct 865 ms 21960 KB Output is correct
93 Correct 803 ms 21960 KB Output is correct
94 Correct 350 ms 21960 KB Output is correct
95 Correct 740 ms 21960 KB Output is correct
96 Correct 730 ms 21960 KB Output is correct
97 Correct 740 ms 21960 KB Output is correct
98 Correct 701 ms 21960 KB Output is correct
99 Correct 757 ms 21960 KB Output is correct
100 Correct 733 ms 21960 KB Output is correct