답안 #1099117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099117 2024-10-10T15:13:54 Z LOLOLO Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
324 ms 18908 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 166 ms 14164 KB Output is correct
12 Correct 181 ms 13644 KB Output is correct
13 Correct 165 ms 12884 KB Output is correct
14 Correct 175 ms 13160 KB Output is correct
15 Correct 198 ms 14160 KB Output is correct
16 Correct 191 ms 13144 KB Output is correct
17 Correct 184 ms 13140 KB Output is correct
18 Correct 115 ms 15188 KB Output is correct
19 Correct 131 ms 12116 KB Output is correct
20 Correct 164 ms 13864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 166 ms 14164 KB Output is correct
12 Correct 181 ms 13644 KB Output is correct
13 Correct 165 ms 12884 KB Output is correct
14 Correct 175 ms 13160 KB Output is correct
15 Correct 198 ms 14160 KB Output is correct
16 Correct 191 ms 13144 KB Output is correct
17 Correct 184 ms 13140 KB Output is correct
18 Correct 115 ms 15188 KB Output is correct
19 Correct 131 ms 12116 KB Output is correct
20 Correct 164 ms 13864 KB Output is correct
21 Correct 324 ms 16980 KB Output is correct
22 Correct 192 ms 17236 KB Output is correct
23 Correct 192 ms 16100 KB Output is correct
24 Correct 192 ms 16140 KB Output is correct
25 Correct 194 ms 18004 KB Output is correct
26 Correct 207 ms 16500 KB Output is correct
27 Correct 213 ms 16724 KB Output is correct
28 Correct 112 ms 18908 KB Output is correct
29 Correct 147 ms 15336 KB Output is correct
30 Correct 255 ms 17488 KB Output is correct
31 Correct 235 ms 17708 KB Output is correct
32 Correct 204 ms 17748 KB Output is correct
33 Correct 186 ms 16720 KB Output is correct
34 Correct 199 ms 16724 KB Output is correct
35 Correct 214 ms 17232 KB Output is correct
36 Correct 103 ms 15700 KB Output is correct
37 Correct 209 ms 17744 KB Output is correct
38 Correct 158 ms 15696 KB Output is correct
39 Correct 197 ms 16964 KB Output is correct
40 Correct 191 ms 16980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 37 ms 16120 KB Output is correct
12 Correct 41 ms 16196 KB Output is correct
13 Correct 40 ms 16112 KB Output is correct
14 Correct 59 ms 16012 KB Output is correct
15 Correct 39 ms 16028 KB Output is correct
16 Incorrect 47 ms 16116 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 166 ms 14164 KB Output is correct
12 Correct 181 ms 13644 KB Output is correct
13 Correct 165 ms 12884 KB Output is correct
14 Correct 175 ms 13160 KB Output is correct
15 Correct 198 ms 14160 KB Output is correct
16 Correct 191 ms 13144 KB Output is correct
17 Correct 184 ms 13140 KB Output is correct
18 Correct 115 ms 15188 KB Output is correct
19 Correct 131 ms 12116 KB Output is correct
20 Correct 164 ms 13864 KB Output is correct
21 Correct 324 ms 16980 KB Output is correct
22 Correct 192 ms 17236 KB Output is correct
23 Correct 192 ms 16100 KB Output is correct
24 Correct 192 ms 16140 KB Output is correct
25 Correct 194 ms 18004 KB Output is correct
26 Correct 207 ms 16500 KB Output is correct
27 Correct 213 ms 16724 KB Output is correct
28 Correct 112 ms 18908 KB Output is correct
29 Correct 147 ms 15336 KB Output is correct
30 Correct 255 ms 17488 KB Output is correct
31 Correct 235 ms 17708 KB Output is correct
32 Correct 204 ms 17748 KB Output is correct
33 Correct 186 ms 16720 KB Output is correct
34 Correct 199 ms 16724 KB Output is correct
35 Correct 214 ms 17232 KB Output is correct
36 Correct 103 ms 15700 KB Output is correct
37 Correct 209 ms 17744 KB Output is correct
38 Correct 158 ms 15696 KB Output is correct
39 Correct 197 ms 16964 KB Output is correct
40 Correct 191 ms 16980 KB Output is correct
41 Correct 37 ms 16120 KB Output is correct
42 Correct 41 ms 16196 KB Output is correct
43 Correct 40 ms 16112 KB Output is correct
44 Correct 59 ms 16012 KB Output is correct
45 Correct 39 ms 16028 KB Output is correct
46 Incorrect 47 ms 16116 KB Output isn't correct
47 Halted 0 ms 0 KB -