답안 #125690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125690 2019-07-06T08:46:22 Z 윤교준(#3070) Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1356 ms 21752 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

int B[1<<20], C[1<<20];
char A[1<<20|1];

int N, Q;

int main() {
	scanf("%d%d %s", &N, &Q, A);

	for(int i = 1<<N, t = (1<<N)-1; i--;)
		B[i] = C[t^i] = A[i]&15;
	for(int j = 0; j < N; j++) {
		for(int i = 1<<N; i--;) if(i & (1<<j)) {
			B[i] += B[i^1<<j];
			C[i] += C[i^1<<j];
		}
	}

	for(char S[22]; Q--;) {
		scanf(" %s", S+1);
		int ret = 0;
		int zb = 0, ob = 0, qb = 0;
		int zbn = 0, obn = 0, qbn = 0;
		for(int i = N; i--;) {
			if('0' == S[N-i]) { zb |= 1<<i; zbn++; }
			else if('1' == S[N-i]) { ob |= 1<<i; obn++; }
			else { qb |= 1<<i; qbn++; }
		}
		if(zbn < 7) {
			for(int key = 0, k;;) {
				ret += (__builtin_popcount(key)&1) ? -C[key|qb] : C[key|qb];
				if(key == zb) break;
				k = 31 - __builtin_clz(rb(zb-key));
				key = key>>k<<k | 1<<k;
			}
		} else if(obn < 7) {
			for(int key = 0, k;;) {
				ret += (__builtin_popcount(key)&1) ? -B[key|qb] : B[key|qb];
				if(key == ob) break;
				k = 31 - __builtin_clz(rb(ob-key));
				key = key>>k<<k | 1<<k;
			}
		} else {
			for(int key = 0, k;;) {
				ret += A[ob|key] & 15;
				if(key == qb) break;
				k = 31 - __builtin_clz(rb(qb-key));
				key = key>>k<<k | 1<<k;
			}
		}
		printf("%d\n", ret < 0 ? -ret : ret);
	}
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d %s", &N, &Q, A);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", S+1);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 266 ms 6264 KB Output is correct
12 Correct 522 ms 5996 KB Output is correct
13 Correct 576 ms 5240 KB Output is correct
14 Correct 447 ms 5368 KB Output is correct
15 Correct 328 ms 6388 KB Output is correct
16 Correct 366 ms 5604 KB Output is correct
17 Correct 446 ms 5440 KB Output is correct
18 Correct 231 ms 7420 KB Output is correct
19 Correct 538 ms 4360 KB Output is correct
20 Correct 282 ms 5880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 266 ms 6264 KB Output is correct
12 Correct 522 ms 5996 KB Output is correct
13 Correct 576 ms 5240 KB Output is correct
14 Correct 447 ms 5368 KB Output is correct
15 Correct 328 ms 6388 KB Output is correct
16 Correct 366 ms 5604 KB Output is correct
17 Correct 446 ms 5440 KB Output is correct
18 Correct 231 ms 7420 KB Output is correct
19 Correct 538 ms 4360 KB Output is correct
20 Correct 282 ms 5880 KB Output is correct
21 Correct 325 ms 6312 KB Output is correct
22 Correct 521 ms 6520 KB Output is correct
23 Correct 935 ms 5608 KB Output is correct
24 Correct 612 ms 5340 KB Output is correct
25 Correct 399 ms 7384 KB Output is correct
26 Correct 517 ms 6108 KB Output is correct
27 Correct 565 ms 5880 KB Output is correct
28 Correct 252 ms 8312 KB Output is correct
29 Correct 895 ms 4348 KB Output is correct
30 Correct 342 ms 6424 KB Output is correct
31 Correct 494 ms 6496 KB Output is correct
32 Correct 502 ms 6528 KB Output is correct
33 Correct 394 ms 5272 KB Output is correct
34 Correct 575 ms 5544 KB Output is correct
35 Correct 563 ms 6020 KB Output is correct
36 Correct 248 ms 4472 KB Output is correct
37 Correct 325 ms 6464 KB Output is correct
38 Correct 664 ms 4448 KB Output is correct
39 Correct 502 ms 5624 KB Output is correct
40 Correct 496 ms 5516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 67 ms 11768 KB Output is correct
12 Correct 68 ms 11868 KB Output is correct
13 Correct 80 ms 11768 KB Output is correct
14 Correct 95 ms 11724 KB Output is correct
15 Correct 72 ms 11896 KB Output is correct
16 Correct 101 ms 11872 KB Output is correct
17 Correct 98 ms 11956 KB Output is correct
18 Correct 59 ms 12008 KB Output is correct
19 Correct 66 ms 11640 KB Output is correct
20 Correct 67 ms 11900 KB Output is correct
21 Correct 82 ms 11788 KB Output is correct
22 Correct 99 ms 11740 KB Output is correct
23 Correct 73 ms 11900 KB Output is correct
24 Correct 97 ms 11820 KB Output is correct
25 Correct 120 ms 11772 KB Output is correct
26 Correct 59 ms 11640 KB Output is correct
27 Correct 66 ms 11896 KB Output is correct
28 Correct 68 ms 11768 KB Output is correct
29 Correct 81 ms 11896 KB Output is correct
30 Correct 85 ms 11768 KB Output is correct
31 Correct 72 ms 11752 KB Output is correct
32 Correct 109 ms 11896 KB Output is correct
33 Correct 95 ms 11768 KB Output is correct
34 Correct 59 ms 11916 KB Output is correct
35 Correct 91 ms 11772 KB Output is correct
36 Correct 89 ms 11896 KB Output is correct
37 Correct 91 ms 11768 KB Output is correct
38 Correct 90 ms 11772 KB Output is correct
39 Correct 89 ms 11768 KB Output is correct
40 Correct 93 ms 11768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 266 ms 6264 KB Output is correct
12 Correct 522 ms 5996 KB Output is correct
13 Correct 576 ms 5240 KB Output is correct
14 Correct 447 ms 5368 KB Output is correct
15 Correct 328 ms 6388 KB Output is correct
16 Correct 366 ms 5604 KB Output is correct
17 Correct 446 ms 5440 KB Output is correct
18 Correct 231 ms 7420 KB Output is correct
19 Correct 538 ms 4360 KB Output is correct
20 Correct 282 ms 5880 KB Output is correct
21 Correct 325 ms 6312 KB Output is correct
22 Correct 521 ms 6520 KB Output is correct
23 Correct 935 ms 5608 KB Output is correct
24 Correct 612 ms 5340 KB Output is correct
25 Correct 399 ms 7384 KB Output is correct
26 Correct 517 ms 6108 KB Output is correct
27 Correct 565 ms 5880 KB Output is correct
28 Correct 252 ms 8312 KB Output is correct
29 Correct 895 ms 4348 KB Output is correct
30 Correct 342 ms 6424 KB Output is correct
31 Correct 494 ms 6496 KB Output is correct
32 Correct 502 ms 6528 KB Output is correct
33 Correct 394 ms 5272 KB Output is correct
34 Correct 575 ms 5544 KB Output is correct
35 Correct 563 ms 6020 KB Output is correct
36 Correct 248 ms 4472 KB Output is correct
37 Correct 325 ms 6464 KB Output is correct
38 Correct 664 ms 4448 KB Output is correct
39 Correct 502 ms 5624 KB Output is correct
40 Correct 496 ms 5516 KB Output is correct
41 Correct 67 ms 11768 KB Output is correct
42 Correct 68 ms 11868 KB Output is correct
43 Correct 80 ms 11768 KB Output is correct
44 Correct 95 ms 11724 KB Output is correct
45 Correct 72 ms 11896 KB Output is correct
46 Correct 101 ms 11872 KB Output is correct
47 Correct 98 ms 11956 KB Output is correct
48 Correct 59 ms 12008 KB Output is correct
49 Correct 66 ms 11640 KB Output is correct
50 Correct 67 ms 11900 KB Output is correct
51 Correct 82 ms 11788 KB Output is correct
52 Correct 99 ms 11740 KB Output is correct
53 Correct 73 ms 11900 KB Output is correct
54 Correct 97 ms 11820 KB Output is correct
55 Correct 120 ms 11772 KB Output is correct
56 Correct 59 ms 11640 KB Output is correct
57 Correct 66 ms 11896 KB Output is correct
58 Correct 68 ms 11768 KB Output is correct
59 Correct 81 ms 11896 KB Output is correct
60 Correct 85 ms 11768 KB Output is correct
61 Correct 72 ms 11752 KB Output is correct
62 Correct 109 ms 11896 KB Output is correct
63 Correct 95 ms 11768 KB Output is correct
64 Correct 59 ms 11916 KB Output is correct
65 Correct 91 ms 11772 KB Output is correct
66 Correct 89 ms 11896 KB Output is correct
67 Correct 91 ms 11768 KB Output is correct
68 Correct 90 ms 11772 KB Output is correct
69 Correct 89 ms 11768 KB Output is correct
70 Correct 93 ms 11768 KB Output is correct
71 Correct 528 ms 18748 KB Output is correct
72 Correct 551 ms 18908 KB Output is correct
73 Correct 823 ms 17400 KB Output is correct
74 Correct 1098 ms 17716 KB Output is correct
75 Correct 619 ms 19676 KB Output is correct
76 Correct 1223 ms 18168 KB Output is correct
77 Correct 1211 ms 17956 KB Output is correct
78 Correct 355 ms 21752 KB Output is correct
79 Correct 465 ms 15864 KB Output is correct
80 Correct 520 ms 18936 KB Output is correct
81 Correct 836 ms 18648 KB Output is correct
82 Correct 1186 ms 17820 KB Output is correct
83 Correct 616 ms 16888 KB Output is correct
84 Correct 1356 ms 17828 KB Output is correct
85 Correct 1274 ms 18012 KB Output is correct
86 Correct 341 ms 15748 KB Output is correct
87 Correct 501 ms 18668 KB Output is correct
88 Correct 531 ms 15712 KB Output is correct
89 Correct 807 ms 17336 KB Output is correct
90 Correct 870 ms 17672 KB Output is correct
91 Correct 619 ms 17016 KB Output is correct
92 Correct 1236 ms 18024 KB Output is correct
93 Correct 1324 ms 17940 KB Output is correct
94 Correct 340 ms 15676 KB Output is correct
95 Correct 1002 ms 17576 KB Output is correct
96 Correct 963 ms 17776 KB Output is correct
97 Correct 964 ms 17784 KB Output is correct
98 Correct 1069 ms 17664 KB Output is correct
99 Correct 957 ms 17628 KB Output is correct
100 Correct 978 ms 17580 KB Output is correct