답안 #1099115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099115 2024-10-10T15:11:58 Z LOLOLO Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
332 ms 20180 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, sum = 0;
    for (int i = 0; i < (1 << n); i++) {
        v[i] = s[i] - '0';
        f1[i] = v[i];
        f2[all ^ i] = v[i];
        sum += 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 += f2[sub | on];
                } else {
                    ans -= f2[sub | on];
                }
            }
        }

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

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 0 ms 472 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 496 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 0 ms 472 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 496 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 158 ms 15204 KB Output is correct
12 Correct 161 ms 14676 KB Output is correct
13 Correct 172 ms 13904 KB Output is correct
14 Correct 159 ms 14164 KB Output is correct
15 Correct 200 ms 15184 KB Output is correct
16 Correct 183 ms 14164 KB Output is correct
17 Correct 210 ms 14152 KB Output is correct
18 Correct 118 ms 16128 KB Output is correct
19 Correct 137 ms 13088 KB Output is correct
20 Correct 182 ms 14664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 0 ms 472 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 496 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 158 ms 15204 KB Output is correct
12 Correct 161 ms 14676 KB Output is correct
13 Correct 172 ms 13904 KB Output is correct
14 Correct 159 ms 14164 KB Output is correct
15 Correct 200 ms 15184 KB Output is correct
16 Correct 183 ms 14164 KB Output is correct
17 Correct 210 ms 14152 KB Output is correct
18 Correct 118 ms 16128 KB Output is correct
19 Correct 137 ms 13088 KB Output is correct
20 Correct 182 ms 14664 KB Output is correct
21 Correct 332 ms 18224 KB Output is correct
22 Correct 198 ms 18256 KB Output is correct
23 Correct 187 ms 17236 KB Output is correct
24 Correct 185 ms 17232 KB Output is correct
25 Correct 183 ms 19248 KB Output is correct
26 Correct 213 ms 17748 KB Output is correct
27 Correct 206 ms 17592 KB Output is correct
28 Correct 127 ms 20180 KB Output is correct
29 Correct 158 ms 16212 KB Output is correct
30 Correct 255 ms 18424 KB Output is correct
31 Correct 234 ms 18260 KB Output is correct
32 Correct 217 ms 18264 KB Output is correct
33 Correct 205 ms 16980 KB Output is correct
34 Correct 205 ms 17236 KB Output is correct
35 Correct 233 ms 17492 KB Output is correct
36 Correct 128 ms 16200 KB Output is correct
37 Correct 209 ms 18204 KB Output is correct
38 Correct 168 ms 16208 KB Output is correct
39 Correct 224 ms 17380 KB Output is correct
40 Correct 190 ms 17232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 0 ms 472 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 496 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 38 ms 16212 KB Output is correct
12 Correct 38 ms 16112 KB Output is correct
13 Correct 40 ms 16124 KB Output is correct
14 Correct 55 ms 16112 KB Output is correct
15 Correct 42 ms 16116 KB Output is correct
16 Incorrect 48 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 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 0 ms 472 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 496 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 158 ms 15204 KB Output is correct
12 Correct 161 ms 14676 KB Output is correct
13 Correct 172 ms 13904 KB Output is correct
14 Correct 159 ms 14164 KB Output is correct
15 Correct 200 ms 15184 KB Output is correct
16 Correct 183 ms 14164 KB Output is correct
17 Correct 210 ms 14152 KB Output is correct
18 Correct 118 ms 16128 KB Output is correct
19 Correct 137 ms 13088 KB Output is correct
20 Correct 182 ms 14664 KB Output is correct
21 Correct 332 ms 18224 KB Output is correct
22 Correct 198 ms 18256 KB Output is correct
23 Correct 187 ms 17236 KB Output is correct
24 Correct 185 ms 17232 KB Output is correct
25 Correct 183 ms 19248 KB Output is correct
26 Correct 213 ms 17748 KB Output is correct
27 Correct 206 ms 17592 KB Output is correct
28 Correct 127 ms 20180 KB Output is correct
29 Correct 158 ms 16212 KB Output is correct
30 Correct 255 ms 18424 KB Output is correct
31 Correct 234 ms 18260 KB Output is correct
32 Correct 217 ms 18264 KB Output is correct
33 Correct 205 ms 16980 KB Output is correct
34 Correct 205 ms 17236 KB Output is correct
35 Correct 233 ms 17492 KB Output is correct
36 Correct 128 ms 16200 KB Output is correct
37 Correct 209 ms 18204 KB Output is correct
38 Correct 168 ms 16208 KB Output is correct
39 Correct 224 ms 17380 KB Output is correct
40 Correct 190 ms 17232 KB Output is correct
41 Correct 38 ms 16212 KB Output is correct
42 Correct 38 ms 16112 KB Output is correct
43 Correct 40 ms 16124 KB Output is correct
44 Correct 55 ms 16112 KB Output is correct
45 Correct 42 ms 16116 KB Output is correct
46 Incorrect 48 ms 16116 KB Output isn't correct
47 Halted 0 ms 0 KB -