답안 #1099118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099118 2024-10-10T15:15:25 Z LOLOLO Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
616 ms 43228 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 1 << 20;
int f1[N], f2[N], v[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    int all = (1 << n) - 1;
    for (int i = 0; i < (1 << n); i++) {
        v[i] = s[i] - '0';
        f1[i] = v[i];
        f2[all ^ i] = v[i];
    }

    for (int i = 0; i < n; i++) {
        for (int mask = (1 << n) - 1; mask >= 0; mask--) {
            if ((mask & (1 << i)))
                continue;

            f1[mask] += f1[mask ^ (1 << i)];
            f2[mask] += f2[mask ^ (1 << i)];
        }
    }

    for (int i = 0; i < q; i++) {
        string s;
        cin >> s;
        int on = 0, off = 0, cc = 0;

        for (int j = 0; j < n; j++) {
            if (s[j] == '1') {
                on |= (1 << (n - j - 1));
            }

            if (s[j] == '0') {
                off |= (1 << (n - j - 1));
            }

            if (s[j] == '?') {
                cc |= (1 << (n - j - 1));
            }
        }

        int ans = 0;
        if (cntbit(cc) <= 6) {
            ans = v[on];
            for (int sub = cc; sub; sub = cc & (sub - 1)) {
                ans += v[sub | on];
            }
        } else if (cntbit(on) <= 6) {
            ans = f2[off];
            for (int sub = on; sub; sub = on & (sub - 1)) {
                if (cntbit(sub) % 2) {
                    ans -= f2[sub | off];
                } else {
                    ans += f2[sub | off];
                }
            }
        } else {
            ans = f1[on];
            for (int sub = off; sub; sub = off & (sub - 1)) {
                if (cntbit(sub) % 2) {
                    ans -= f1[sub | on];
                } else {
                    ans += f1[sub | on];
                }
            }
        }

        cout << ans << '\n';
    }
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 476 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 476 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 476 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 476 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 170 ms 14384 KB Output is correct
12 Correct 167 ms 13908 KB Output is correct
13 Correct 167 ms 13136 KB Output is correct
14 Correct 179 ms 13396 KB Output is correct
15 Correct 197 ms 14252 KB Output is correct
16 Correct 184 ms 13396 KB Output is correct
17 Correct 185 ms 13604 KB Output is correct
18 Correct 102 ms 15452 KB Output is correct
19 Correct 130 ms 12384 KB Output is correct
20 Correct 164 ms 13960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 476 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 476 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 170 ms 14384 KB Output is correct
12 Correct 167 ms 13908 KB Output is correct
13 Correct 167 ms 13136 KB Output is correct
14 Correct 179 ms 13396 KB Output is correct
15 Correct 197 ms 14252 KB Output is correct
16 Correct 184 ms 13396 KB Output is correct
17 Correct 185 ms 13604 KB Output is correct
18 Correct 102 ms 15452 KB Output is correct
19 Correct 130 ms 12384 KB Output is correct
20 Correct 164 ms 13960 KB Output is correct
21 Correct 323 ms 16980 KB Output is correct
22 Correct 184 ms 16980 KB Output is correct
23 Correct 199 ms 15952 KB Output is correct
24 Correct 186 ms 15884 KB Output is correct
25 Correct 198 ms 17964 KB Output is correct
26 Correct 207 ms 16256 KB Output is correct
27 Correct 210 ms 16208 KB Output is correct
28 Correct 112 ms 18780 KB Output is correct
29 Correct 149 ms 14932 KB Output is correct
30 Correct 251 ms 15304 KB Output is correct
31 Correct 240 ms 15184 KB Output is correct
32 Correct 215 ms 14956 KB Output is correct
33 Correct 188 ms 14160 KB Output is correct
34 Correct 189 ms 14160 KB Output is correct
35 Correct 214 ms 14448 KB Output is correct
36 Correct 105 ms 13192 KB Output is correct
37 Correct 203 ms 14944 KB Output is correct
38 Correct 178 ms 13140 KB Output is correct
39 Correct 223 ms 14160 KB Output is correct
40 Correct 204 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 476 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 476 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 38 ms 16112 KB Output is correct
12 Correct 44 ms 16116 KB Output is correct
13 Correct 45 ms 16116 KB Output is correct
14 Correct 57 ms 16120 KB Output is correct
15 Correct 42 ms 16116 KB Output is correct
16 Correct 54 ms 16116 KB Output is correct
17 Correct 48 ms 16116 KB Output is correct
18 Correct 35 ms 16116 KB Output is correct
19 Correct 39 ms 15956 KB Output is correct
20 Correct 41 ms 16048 KB Output is correct
21 Correct 48 ms 16116 KB Output is correct
22 Correct 53 ms 16004 KB Output is correct
23 Correct 41 ms 16100 KB Output is correct
24 Correct 48 ms 16120 KB Output is correct
25 Correct 50 ms 15952 KB Output is correct
26 Correct 49 ms 15920 KB Output is correct
27 Correct 38 ms 16120 KB Output is correct
28 Correct 41 ms 15860 KB Output is correct
29 Correct 43 ms 16116 KB Output is correct
30 Correct 44 ms 16120 KB Output is correct
31 Correct 43 ms 15960 KB Output is correct
32 Correct 50 ms 16116 KB Output is correct
33 Correct 48 ms 16116 KB Output is correct
34 Correct 34 ms 15872 KB Output is correct
35 Correct 43 ms 15912 KB Output is correct
36 Correct 46 ms 15952 KB Output is correct
37 Correct 42 ms 16116 KB Output is correct
38 Correct 53 ms 15960 KB Output is correct
39 Correct 42 ms 16124 KB Output is correct
40 Correct 43 ms 15956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 476 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 476 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 170 ms 14384 KB Output is correct
12 Correct 167 ms 13908 KB Output is correct
13 Correct 167 ms 13136 KB Output is correct
14 Correct 179 ms 13396 KB Output is correct
15 Correct 197 ms 14252 KB Output is correct
16 Correct 184 ms 13396 KB Output is correct
17 Correct 185 ms 13604 KB Output is correct
18 Correct 102 ms 15452 KB Output is correct
19 Correct 130 ms 12384 KB Output is correct
20 Correct 164 ms 13960 KB Output is correct
21 Correct 323 ms 16980 KB Output is correct
22 Correct 184 ms 16980 KB Output is correct
23 Correct 199 ms 15952 KB Output is correct
24 Correct 186 ms 15884 KB Output is correct
25 Correct 198 ms 17964 KB Output is correct
26 Correct 207 ms 16256 KB Output is correct
27 Correct 210 ms 16208 KB Output is correct
28 Correct 112 ms 18780 KB Output is correct
29 Correct 149 ms 14932 KB Output is correct
30 Correct 251 ms 15304 KB Output is correct
31 Correct 240 ms 15184 KB Output is correct
32 Correct 215 ms 14956 KB Output is correct
33 Correct 188 ms 14160 KB Output is correct
34 Correct 189 ms 14160 KB Output is correct
35 Correct 214 ms 14448 KB Output is correct
36 Correct 105 ms 13192 KB Output is correct
37 Correct 203 ms 14944 KB Output is correct
38 Correct 178 ms 13140 KB Output is correct
39 Correct 223 ms 14160 KB Output is correct
40 Correct 204 ms 14164 KB Output is correct
41 Correct 38 ms 16112 KB Output is correct
42 Correct 44 ms 16116 KB Output is correct
43 Correct 45 ms 16116 KB Output is correct
44 Correct 57 ms 16120 KB Output is correct
45 Correct 42 ms 16116 KB Output is correct
46 Correct 54 ms 16116 KB Output is correct
47 Correct 48 ms 16116 KB Output is correct
48 Correct 35 ms 16116 KB Output is correct
49 Correct 39 ms 15956 KB Output is correct
50 Correct 41 ms 16048 KB Output is correct
51 Correct 48 ms 16116 KB Output is correct
52 Correct 53 ms 16004 KB Output is correct
53 Correct 41 ms 16100 KB Output is correct
54 Correct 48 ms 16120 KB Output is correct
55 Correct 50 ms 15952 KB Output is correct
56 Correct 49 ms 15920 KB Output is correct
57 Correct 38 ms 16120 KB Output is correct
58 Correct 41 ms 15860 KB Output is correct
59 Correct 43 ms 16116 KB Output is correct
60 Correct 44 ms 16120 KB Output is correct
61 Correct 43 ms 15960 KB Output is correct
62 Correct 50 ms 16116 KB Output is correct
63 Correct 48 ms 16116 KB Output is correct
64 Correct 34 ms 15872 KB Output is correct
65 Correct 43 ms 15912 KB Output is correct
66 Correct 46 ms 15952 KB Output is correct
67 Correct 42 ms 16116 KB Output is correct
68 Correct 53 ms 15960 KB Output is correct
69 Correct 42 ms 16124 KB Output is correct
70 Correct 43 ms 15956 KB Output is correct
71 Correct 247 ms 40356 KB Output is correct
72 Correct 288 ms 40436 KB Output is correct
73 Correct 321 ms 38996 KB Output is correct
74 Correct 616 ms 39256 KB Output is correct
75 Correct 308 ms 41328 KB Output is correct
76 Correct 493 ms 39672 KB Output is correct
77 Correct 430 ms 39504 KB Output is correct
78 Correct 199 ms 43228 KB Output is correct
79 Correct 268 ms 37364 KB Output is correct
80 Correct 313 ms 40432 KB Output is correct
81 Correct 390 ms 40432 KB Output is correct
82 Correct 537 ms 39408 KB Output is correct
83 Correct 298 ms 38404 KB Output is correct
84 Correct 374 ms 39392 KB Output is correct
85 Correct 455 ms 39416 KB Output is correct
86 Correct 180 ms 37432 KB Output is correct
87 Correct 306 ms 40280 KB Output is correct
88 Correct 299 ms 37228 KB Output is correct
89 Correct 372 ms 38900 KB Output is correct
90 Correct 406 ms 39416 KB Output is correct
91 Correct 291 ms 38480 KB Output is correct
92 Correct 572 ms 39404 KB Output is correct
93 Correct 475 ms 39412 KB Output is correct
94 Correct 210 ms 37352 KB Output is correct
95 Correct 410 ms 39508 KB Output is correct
96 Correct 415 ms 39492 KB Output is correct
97 Correct 373 ms 39496 KB Output is correct
98 Correct 399 ms 39504 KB Output is correct
99 Correct 446 ms 39412 KB Output is correct
100 Correct 372 ms 39408 KB Output is correct