Submission #674300

# Submission time Handle Problem Language Result Execution time Memory
674300 2022-12-23T16:44:11 Z Kahou Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
831 ms 42096 KB
/* In the name of God, aka Allah */
// let this be mytemp.cpp
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int M = (1<<20) + 50, N = 3;
int l, q, f[M], dp[2][M];
int A[3];

void solve() {
        cin >> l >> q;
        for (int mask = 0; mask < (1<<l); mask++) {
                char c;
                cin >> c;
                dp[0][mask] = dp[1][mask] = f[mask] = c-'0';
        }
        for (int i = 0; i < l; i++) {
                for (int mask = 0; mask < (1<<l); mask++) {
                        if (mask>>i&1) dp[0][mask] += dp[0][mask^(1<<i)];
                        else dp[1][mask] += dp[1][mask^(1<<i)];
                }
        }
        while (q--) {
                string t;
                cin >> t;

                A[0] = A[1] = A[2] = 0;
                int ans = 0;
                for (int i = 0; i < l; i++) {
                        int c = (t[i] != '0') + (t[i] == '?');
                        A[c] ^= 1<<(l-i-1);
                }
                int m = 0;
                if (__builtin_popcount(A[1]) < __builtin_popcount(A[m])) m = 1;
                if (__builtin_popcount(A[2]) < __builtin_popcount(A[m])) m = 2;
                if (m == 0) {
                        ans = dp[1][A[1]];
                        for (int mask = A[0]; mask > 0; mask = (mask-1)&A[0]) {
                                ans += (__builtin_popcount(mask)&1? -1:1)*dp[1][mask^A[1]];
                        }
                }
                else if (m == 1) {
                        ans = (__builtin_popcount(A[1])&1? -1:1)* dp[0][A[2]];
                        for (int mask = A[1]; mask > 0; mask = (mask-1)&A[1]) {
                                ans += (__builtin_popcount(mask^A[1])&1? -1:1)* dp[0][mask^A[2]];
                        }
                }
                else {
                        ans = f[A[1]];
                        for (int mask = A[2]; mask > 0; mask = (mask-1)&A[2]) {
                                ans += f[mask^A[1]];
                        }
                }
                cout << ans << endl;
        }
}
int main() {
        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        solve();
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 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 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 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 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 199 ms 15052 KB Output is correct
12 Correct 217 ms 14704 KB Output is correct
13 Correct 231 ms 14012 KB Output is correct
14 Correct 222 ms 14104 KB Output is correct
15 Correct 207 ms 15056 KB Output is correct
16 Correct 231 ms 14224 KB Output is correct
17 Correct 213 ms 14236 KB Output is correct
18 Correct 197 ms 16036 KB Output is correct
19 Correct 205 ms 12988 KB Output is correct
20 Correct 202 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 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 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 199 ms 15052 KB Output is correct
12 Correct 217 ms 14704 KB Output is correct
13 Correct 231 ms 14012 KB Output is correct
14 Correct 222 ms 14104 KB Output is correct
15 Correct 207 ms 15056 KB Output is correct
16 Correct 231 ms 14224 KB Output is correct
17 Correct 213 ms 14236 KB Output is correct
18 Correct 197 ms 16036 KB Output is correct
19 Correct 205 ms 12988 KB Output is correct
20 Correct 202 ms 14684 KB Output is correct
21 Correct 214 ms 18044 KB Output is correct
22 Correct 309 ms 18260 KB Output is correct
23 Correct 347 ms 17272 KB Output is correct
24 Correct 267 ms 17064 KB Output is correct
25 Correct 248 ms 19116 KB Output is correct
26 Correct 277 ms 17520 KB Output is correct
27 Correct 249 ms 17468 KB Output is correct
28 Correct 216 ms 20060 KB Output is correct
29 Correct 197 ms 16120 KB Output is correct
30 Correct 224 ms 18172 KB Output is correct
31 Correct 244 ms 18060 KB Output is correct
32 Correct 301 ms 18092 KB Output is correct
33 Correct 239 ms 16912 KB Output is correct
34 Correct 257 ms 17028 KB Output is correct
35 Correct 259 ms 17452 KB Output is correct
36 Correct 209 ms 16096 KB Output is correct
37 Correct 218 ms 18124 KB Output is correct
38 Correct 216 ms 16180 KB Output is correct
39 Correct 245 ms 17324 KB Output is correct
40 Correct 254 ms 17028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 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 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 64 ms 14896 KB Output is correct
12 Correct 51 ms 14836 KB Output is correct
13 Correct 55 ms 14824 KB Output is correct
14 Correct 80 ms 14776 KB Output is correct
15 Correct 51 ms 14896 KB Output is correct
16 Correct 79 ms 14768 KB Output is correct
17 Correct 68 ms 14796 KB Output is correct
18 Correct 50 ms 15024 KB Output is correct
19 Correct 52 ms 14660 KB Output is correct
20 Correct 50 ms 14928 KB Output is correct
21 Correct 63 ms 14796 KB Output is correct
22 Correct 65 ms 14780 KB Output is correct
23 Correct 53 ms 14796 KB Output is correct
24 Correct 72 ms 14772 KB Output is correct
25 Correct 74 ms 14872 KB Output is correct
26 Correct 50 ms 14744 KB Output is correct
27 Correct 50 ms 14896 KB Output is correct
28 Correct 52 ms 14708 KB Output is correct
29 Correct 57 ms 14732 KB Output is correct
30 Correct 56 ms 14764 KB Output is correct
31 Correct 50 ms 14800 KB Output is correct
32 Correct 73 ms 14880 KB Output is correct
33 Correct 72 ms 14860 KB Output is correct
34 Correct 57 ms 14836 KB Output is correct
35 Correct 65 ms 14768 KB Output is correct
36 Correct 64 ms 14808 KB Output is correct
37 Correct 62 ms 14788 KB Output is correct
38 Correct 62 ms 14776 KB Output is correct
39 Correct 68 ms 14840 KB Output is correct
40 Correct 73 ms 14796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 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 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 199 ms 15052 KB Output is correct
12 Correct 217 ms 14704 KB Output is correct
13 Correct 231 ms 14012 KB Output is correct
14 Correct 222 ms 14104 KB Output is correct
15 Correct 207 ms 15056 KB Output is correct
16 Correct 231 ms 14224 KB Output is correct
17 Correct 213 ms 14236 KB Output is correct
18 Correct 197 ms 16036 KB Output is correct
19 Correct 205 ms 12988 KB Output is correct
20 Correct 202 ms 14684 KB Output is correct
21 Correct 214 ms 18044 KB Output is correct
22 Correct 309 ms 18260 KB Output is correct
23 Correct 347 ms 17272 KB Output is correct
24 Correct 267 ms 17064 KB Output is correct
25 Correct 248 ms 19116 KB Output is correct
26 Correct 277 ms 17520 KB Output is correct
27 Correct 249 ms 17468 KB Output is correct
28 Correct 216 ms 20060 KB Output is correct
29 Correct 197 ms 16120 KB Output is correct
30 Correct 224 ms 18172 KB Output is correct
31 Correct 244 ms 18060 KB Output is correct
32 Correct 301 ms 18092 KB Output is correct
33 Correct 239 ms 16912 KB Output is correct
34 Correct 257 ms 17028 KB Output is correct
35 Correct 259 ms 17452 KB Output is correct
36 Correct 209 ms 16096 KB Output is correct
37 Correct 218 ms 18124 KB Output is correct
38 Correct 216 ms 16180 KB Output is correct
39 Correct 245 ms 17324 KB Output is correct
40 Correct 254 ms 17028 KB Output is correct
41 Correct 64 ms 14896 KB Output is correct
42 Correct 51 ms 14836 KB Output is correct
43 Correct 55 ms 14824 KB Output is correct
44 Correct 80 ms 14776 KB Output is correct
45 Correct 51 ms 14896 KB Output is correct
46 Correct 79 ms 14768 KB Output is correct
47 Correct 68 ms 14796 KB Output is correct
48 Correct 50 ms 15024 KB Output is correct
49 Correct 52 ms 14660 KB Output is correct
50 Correct 50 ms 14928 KB Output is correct
51 Correct 63 ms 14796 KB Output is correct
52 Correct 65 ms 14780 KB Output is correct
53 Correct 53 ms 14796 KB Output is correct
54 Correct 72 ms 14772 KB Output is correct
55 Correct 74 ms 14872 KB Output is correct
56 Correct 50 ms 14744 KB Output is correct
57 Correct 50 ms 14896 KB Output is correct
58 Correct 52 ms 14708 KB Output is correct
59 Correct 57 ms 14732 KB Output is correct
60 Correct 56 ms 14764 KB Output is correct
61 Correct 50 ms 14800 KB Output is correct
62 Correct 73 ms 14880 KB Output is correct
63 Correct 72 ms 14860 KB Output is correct
64 Correct 57 ms 14836 KB Output is correct
65 Correct 65 ms 14768 KB Output is correct
66 Correct 64 ms 14808 KB Output is correct
67 Correct 62 ms 14788 KB Output is correct
68 Correct 62 ms 14776 KB Output is correct
69 Correct 68 ms 14840 KB Output is correct
70 Correct 73 ms 14796 KB Output is correct
71 Correct 332 ms 39148 KB Output is correct
72 Correct 334 ms 39200 KB Output is correct
73 Correct 465 ms 37812 KB Output is correct
74 Correct 681 ms 38272 KB Output is correct
75 Correct 371 ms 40196 KB Output is correct
76 Correct 705 ms 38608 KB Output is correct
77 Correct 767 ms 38496 KB Output is correct
78 Correct 324 ms 42096 KB Output is correct
79 Correct 318 ms 36096 KB Output is correct
80 Correct 359 ms 39204 KB Output is correct
81 Correct 496 ms 39260 KB Output is correct
82 Correct 653 ms 38356 KB Output is correct
83 Correct 355 ms 37344 KB Output is correct
84 Correct 800 ms 38124 KB Output is correct
85 Correct 675 ms 38456 KB Output is correct
86 Correct 312 ms 36284 KB Output is correct
87 Correct 333 ms 39136 KB Output is correct
88 Correct 367 ms 36268 KB Output is correct
89 Correct 469 ms 37824 KB Output is correct
90 Correct 422 ms 38116 KB Output is correct
91 Correct 359 ms 37308 KB Output is correct
92 Correct 831 ms 38368 KB Output is correct
93 Correct 679 ms 38312 KB Output is correct
94 Correct 298 ms 36148 KB Output is correct
95 Correct 639 ms 38236 KB Output is correct
96 Correct 605 ms 38328 KB Output is correct
97 Correct 580 ms 38256 KB Output is correct
98 Correct 583 ms 38232 KB Output is correct
99 Correct 585 ms 38228 KB Output is correct
100 Correct 595 ms 38168 KB Output is correct