답안 #873636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873636 2023-11-15T12:13:08 Z tvladm2009 Snake Escaping (JOI18_snake_escaping) C++17
0 / 100
1 ms 4572 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int L = 21;
const int M = (1 << L) + 7;
const int K = 6;

int m;
int l;
int q;
string s;
int a[M];
int f[M];
int g[M];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> l >> q >> s;
    m = (1 << l);
    for (int i = 0; i < m; ++i) {
        a[i] = s[i] - '0';
    }
    for (int i = 0; i < m; ++i) {
        f[i] = a[i];
        g[i] = a[i];
    }
    for (int j = 0; j < l; ++j) {
        for (int i = 0; i < m; ++i) {
            if ((i >> j) & 1) {
                f[i] += f[i ^ (1 << j)];
                g[i ^ (1 << j)] += g[i];
            }
        }
    }
    while (q--) {
        vector<int> t(3, 0);
        string tt;
        cin >> tt;
        for (int i = l - 1; i >= 0; --i) {
            t[tt[i] == '?' ? 2 : tt[i] - '0'] |= (1 << (l - i - 1));
        }
        if (__builtin_popcount(t[1]) <= K) {
            int ans = 0;
            int ppc = __builtin_popcount(t[1]);
            for (int z = t[1]; ; z = (z - 1) & t[1]) {
                ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * f[t[2] | z];
                if (z == 0) {
                    break;
                }
            }
            cout << ans << "\n";
        } else if (__builtin_popcount(t[0]) <= K) {
            int ans = 0;
            int ppc = __builtin_popcount(t[0]);
            for (int z = t[0]; ; z = (z - 1) & t[0]) {
                ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * f[t[0] ^ t[1] ^ z];
                if (z == 0) {
                    break;
                }
            }
            cout << ans << "\n";
        } else {
            assert(__builtin_popcount(t[2]) <= K);
            int ans = 0;
            for (int z = t[2]; ; z = (z - 1) & t[2]) {
                ans += a[t[1] | z];
                if (z == 0) {
                    break;
                }
            }
            cout << ans << "\n";
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4568 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4572 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4568 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4572 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4568 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4572 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4568 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4572 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4568 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4572 KB Output isn't correct
7 Halted 0 ms 0 KB -