답안 #582463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
582463 2022-06-23T20:38:54 Z penguinhacker Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
935 ms 39200 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

int n, q, sub[1<<20], super[1<<20];
string s;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q >> s;
	for (int i=0; i<1<<n; ++i)
		sub[i]=super[i]=s[i]-'0';
	for (int j=0; j<n; ++j)
		for (int i=0; i<1<<n; ++i) {
			if (i&1<<j)
				sub[i]+=sub[i^(1<<j)];
			else
				super[i]+=super[i^(1<<j)];
		}
	while(q--) {
		string t;
		cin >> t;
		reverse(t.begin(), t.end());
		if (count(t.begin(), t.end(), '?')<=6) {
			int a=0, b=0;
			for (int i=0; i<n; ++i) {
				if (t[i]=='?')
					b|=1<<i;
				else if (t[i]=='1')
					a|=1<<i;
			}
			int ans=s[a]-'0';
			for (int c=b; c; c=b&(c-1))
				ans+=s[a|c]-'0';
			cout << ans << "\n";
		} else if (count(t.begin(), t.end(), '1')<=6) {
			int a=0, b=0;
			for (int i=0; i<n; ++i) {
				if (t[i]=='?')
					a|=1<<i;
				else if (t[i]=='1')
					b|=1<<i;
			}
			int ans=sub[a|b];
			for (int c=b; c; c=b&(c-1))
				ans+=(__builtin_popcount(c)%2?-1:1)*sub[(a|b)^c];
			cout << ans << "\n";
		} else {
			int a=0, b=0;
			for (int i=0; i<n; ++i) {
				if (t[i]=='1')
					a|=1<<i;
				else if (t[i]=='0')
					b|=1<<i;
			}
			int ans=super[a];
			for (int c=b; c; c=b&(c-1))
				ans+=(__builtin_popcount(c)%2?-1:1)*super[a|c];
			cout << ans << "\n";
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 257 ms 14996 KB Output is correct
12 Correct 250 ms 14700 KB Output is correct
13 Correct 192 ms 14040 KB Output is correct
14 Correct 203 ms 14064 KB Output is correct
15 Correct 297 ms 15048 KB Output is correct
16 Correct 218 ms 14196 KB Output is correct
17 Correct 226 ms 14284 KB Output is correct
18 Correct 182 ms 16076 KB Output is correct
19 Correct 182 ms 12980 KB Output is correct
20 Correct 250 ms 14736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 257 ms 14996 KB Output is correct
12 Correct 250 ms 14700 KB Output is correct
13 Correct 192 ms 14040 KB Output is correct
14 Correct 203 ms 14064 KB Output is correct
15 Correct 297 ms 15048 KB Output is correct
16 Correct 218 ms 14196 KB Output is correct
17 Correct 226 ms 14284 KB Output is correct
18 Correct 182 ms 16076 KB Output is correct
19 Correct 182 ms 12980 KB Output is correct
20 Correct 250 ms 14736 KB Output is correct
21 Correct 486 ms 18016 KB Output is correct
22 Correct 259 ms 18340 KB Output is correct
23 Correct 234 ms 17228 KB Output is correct
24 Correct 240 ms 17136 KB Output is correct
25 Correct 273 ms 19060 KB Output is correct
26 Correct 259 ms 17664 KB Output is correct
27 Correct 259 ms 17668 KB Output is correct
28 Correct 199 ms 20188 KB Output is correct
29 Correct 187 ms 16148 KB Output is correct
30 Correct 348 ms 18224 KB Output is correct
31 Correct 298 ms 18120 KB Output is correct
32 Correct 293 ms 18120 KB Output is correct
33 Correct 203 ms 16924 KB Output is correct
34 Correct 234 ms 17120 KB Output is correct
35 Correct 243 ms 17576 KB Output is correct
36 Correct 228 ms 16004 KB Output is correct
37 Correct 291 ms 18108 KB Output is correct
38 Correct 221 ms 16072 KB Output is correct
39 Correct 229 ms 17312 KB Output is correct
40 Correct 232 ms 17204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 52 ms 11976 KB Output is correct
12 Correct 52 ms 11964 KB Output is correct
13 Correct 47 ms 11868 KB Output is correct
14 Correct 62 ms 11896 KB Output is correct
15 Correct 47 ms 12084 KB Output is correct
16 Correct 64 ms 11836 KB Output is correct
17 Correct 61 ms 11952 KB Output is correct
18 Correct 43 ms 12100 KB Output is correct
19 Correct 38 ms 11720 KB Output is correct
20 Correct 49 ms 11992 KB Output is correct
21 Correct 53 ms 11928 KB Output is correct
22 Correct 75 ms 11880 KB Output is correct
23 Correct 44 ms 11924 KB Output is correct
24 Correct 47 ms 11812 KB Output is correct
25 Correct 59 ms 11812 KB Output is correct
26 Correct 39 ms 11736 KB Output is correct
27 Correct 42 ms 11968 KB Output is correct
28 Correct 38 ms 11712 KB Output is correct
29 Correct 54 ms 11820 KB Output is correct
30 Correct 45 ms 11884 KB Output is correct
31 Correct 50 ms 11848 KB Output is correct
32 Correct 61 ms 12004 KB Output is correct
33 Correct 64 ms 11920 KB Output is correct
34 Correct 38 ms 11708 KB Output is correct
35 Correct 50 ms 11816 KB Output is correct
36 Correct 56 ms 11904 KB Output is correct
37 Correct 51 ms 11832 KB Output is correct
38 Correct 57 ms 11836 KB Output is correct
39 Correct 49 ms 11848 KB Output is correct
40 Correct 52 ms 11836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 257 ms 14996 KB Output is correct
12 Correct 250 ms 14700 KB Output is correct
13 Correct 192 ms 14040 KB Output is correct
14 Correct 203 ms 14064 KB Output is correct
15 Correct 297 ms 15048 KB Output is correct
16 Correct 218 ms 14196 KB Output is correct
17 Correct 226 ms 14284 KB Output is correct
18 Correct 182 ms 16076 KB Output is correct
19 Correct 182 ms 12980 KB Output is correct
20 Correct 250 ms 14736 KB Output is correct
21 Correct 486 ms 18016 KB Output is correct
22 Correct 259 ms 18340 KB Output is correct
23 Correct 234 ms 17228 KB Output is correct
24 Correct 240 ms 17136 KB Output is correct
25 Correct 273 ms 19060 KB Output is correct
26 Correct 259 ms 17664 KB Output is correct
27 Correct 259 ms 17668 KB Output is correct
28 Correct 199 ms 20188 KB Output is correct
29 Correct 187 ms 16148 KB Output is correct
30 Correct 348 ms 18224 KB Output is correct
31 Correct 298 ms 18120 KB Output is correct
32 Correct 293 ms 18120 KB Output is correct
33 Correct 203 ms 16924 KB Output is correct
34 Correct 234 ms 17120 KB Output is correct
35 Correct 243 ms 17576 KB Output is correct
36 Correct 228 ms 16004 KB Output is correct
37 Correct 291 ms 18108 KB Output is correct
38 Correct 221 ms 16072 KB Output is correct
39 Correct 229 ms 17312 KB Output is correct
40 Correct 232 ms 17204 KB Output is correct
41 Correct 52 ms 11976 KB Output is correct
42 Correct 52 ms 11964 KB Output is correct
43 Correct 47 ms 11868 KB Output is correct
44 Correct 62 ms 11896 KB Output is correct
45 Correct 47 ms 12084 KB Output is correct
46 Correct 64 ms 11836 KB Output is correct
47 Correct 61 ms 11952 KB Output is correct
48 Correct 43 ms 12100 KB Output is correct
49 Correct 38 ms 11720 KB Output is correct
50 Correct 49 ms 11992 KB Output is correct
51 Correct 53 ms 11928 KB Output is correct
52 Correct 75 ms 11880 KB Output is correct
53 Correct 44 ms 11924 KB Output is correct
54 Correct 47 ms 11812 KB Output is correct
55 Correct 59 ms 11812 KB Output is correct
56 Correct 39 ms 11736 KB Output is correct
57 Correct 42 ms 11968 KB Output is correct
58 Correct 38 ms 11712 KB Output is correct
59 Correct 54 ms 11820 KB Output is correct
60 Correct 45 ms 11884 KB Output is correct
61 Correct 50 ms 11848 KB Output is correct
62 Correct 61 ms 12004 KB Output is correct
63 Correct 64 ms 11920 KB Output is correct
64 Correct 38 ms 11708 KB Output is correct
65 Correct 50 ms 11816 KB Output is correct
66 Correct 56 ms 11904 KB Output is correct
67 Correct 51 ms 11832 KB Output is correct
68 Correct 57 ms 11836 KB Output is correct
69 Correct 49 ms 11848 KB Output is correct
70 Correct 52 ms 11836 KB Output is correct
71 Correct 458 ms 36224 KB Output is correct
72 Correct 462 ms 36396 KB Output is correct
73 Correct 367 ms 34856 KB Output is correct
74 Correct 775 ms 35260 KB Output is correct
75 Correct 435 ms 37232 KB Output is correct
76 Correct 813 ms 35648 KB Output is correct
77 Correct 613 ms 35488 KB Output is correct
78 Correct 326 ms 39200 KB Output is correct
79 Correct 268 ms 33256 KB Output is correct
80 Correct 429 ms 36300 KB Output is correct
81 Correct 576 ms 36248 KB Output is correct
82 Correct 935 ms 35268 KB Output is correct
83 Correct 311 ms 34360 KB Output is correct
84 Correct 411 ms 35276 KB Output is correct
85 Correct 611 ms 35384 KB Output is correct
86 Correct 288 ms 33232 KB Output is correct
87 Correct 405 ms 36180 KB Output is correct
88 Correct 289 ms 33272 KB Output is correct
89 Correct 384 ms 34948 KB Output is correct
90 Correct 408 ms 35264 KB Output is correct
91 Correct 325 ms 34400 KB Output is correct
92 Correct 687 ms 35564 KB Output is correct
93 Correct 603 ms 35416 KB Output is correct
94 Correct 266 ms 33280 KB Output is correct
95 Correct 524 ms 35320 KB Output is correct
96 Correct 544 ms 35252 KB Output is correct
97 Correct 550 ms 35488 KB Output is correct
98 Correct 563 ms 35460 KB Output is correct
99 Correct 526 ms 35364 KB Output is correct
100 Correct 524 ms 35268 KB Output is correct