답안 #1100360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100360 2024-10-13T15:09:32 Z KietJ Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
275 ms 24140 KB
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb(x) push_back(x)
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define un(x) (x).erase(unique(all(x)), x.end())

typedef long long ll;
typedef double db;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector <ll> V;

const int N = 1e7 + 1;
const int M = (1 << 20);
const int mod = 1e9 + 7;
const int inf = 1061109567;
const int block = 490;

template <class T1, class Gz> void add(T1 &x, Gz y) { x += y; if (x < 0) x += mod; if (x >= mod) x -= mod; }
template <class T1, class Gz> bool maximize(T1 &x, Gz y) { if (x < y) { x = y; return true; } return false; }
template <class T1, class Gz> bool minimize(T1 &x, Gz y) { if (x > y) { x = y; return true; } return false; }

int n, q, a[M];
ll dp[2][M];

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

    cin >> n >> q;

    for(int i = 0; i < (1 << n); i++) {
        char x; cin >> x;
        a[i] = x - '0';
        for(int j = 0; j < 2; j++)  
            dp[j][i] = a[i];
    }

    for(int i = 0; i < n; i++) {
        for(int mask = 0; mask < (1 << n); mask++) {
            if (mask >> i & 1) {
                dp[0][mask ^ (1 << i)] += dp[0][mask]; 
                dp[1][mask] += dp[1][mask ^ (1 << i)]; 
            }
        }
    }

    for(int i = 1; i <= q; i++) {
        string s; cin >> s;
        reverse(all(s));

        vector <int> mask(3, 0);

        for(int j = 0; j < n; j++) {
            char x = s[j];
            if (x == '0') mask[0] ^= (1 << j);
            if (x == '1') mask[1] ^= (1 << j);
            if (x == '?') mask[2] ^= (1 << j);
        }

        ll ans = 0;
        if (__builtin_popcount(mask[2]) <= 6) {
            ans = a[mask[1]];
            for(int mask1 = mask[2]; mask1; mask1 = (mask1 - 1) & mask[2]) {
                ans += a[mask[1] ^ mask1];
            }
        } else {
            if (__builtin_popcount(mask[0]) <= 6) {
                ans = dp[0][mask[1]];
                for(int mask1 = mask[0]; mask1; mask1 = (mask1 - 1) & mask[0]) {
                    if (__builtin_popcount(mask1) & 1) {
                        ans -= dp[0][mask[1] ^ mask1];
                    } else {
                        ans += dp[0][mask[1] ^ mask1];
                    }
                }
            } else {
                ans = dp[1][mask[1] ^ mask[2]];
                for(int mask1 = mask[1]; mask1; mask1 = (mask1 - 1) & mask[1]) {
                    if (__builtin_popcount(mask1) & 1) {
                        ans -= dp[1][mask1];
                    }  else {
                        ans += dp[1][mask1];
                    }
                }
            }
        } cout << ans << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 1 ms 4436 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4580 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 1 ms 4436 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4580 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
11 Correct 185 ms 19348 KB Output is correct
12 Correct 199 ms 19020 KB Output is correct
13 Correct 200 ms 18256 KB Output is correct
14 Correct 197 ms 18148 KB Output is correct
15 Correct 222 ms 19276 KB Output is correct
16 Correct 206 ms 18516 KB Output is correct
17 Correct 208 ms 18284 KB Output is correct
18 Correct 138 ms 20300 KB Output is correct
19 Correct 151 ms 17228 KB Output is correct
20 Correct 191 ms 19020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 1 ms 4436 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4580 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
11 Correct 185 ms 19348 KB Output is correct
12 Correct 199 ms 19020 KB Output is correct
13 Correct 200 ms 18256 KB Output is correct
14 Correct 197 ms 18148 KB Output is correct
15 Correct 222 ms 19276 KB Output is correct
16 Correct 206 ms 18516 KB Output is correct
17 Correct 208 ms 18284 KB Output is correct
18 Correct 138 ms 20300 KB Output is correct
19 Correct 151 ms 17228 KB Output is correct
20 Correct 191 ms 19020 KB Output is correct
21 Correct 187 ms 22168 KB Output is correct
22 Correct 275 ms 22348 KB Output is correct
23 Correct 242 ms 21324 KB Output is correct
24 Correct 230 ms 21180 KB Output is correct
25 Correct 229 ms 23116 KB Output is correct
26 Correct 252 ms 22000 KB Output is correct
27 Correct 252 ms 21580 KB Output is correct
28 Correct 139 ms 24140 KB Output is correct
29 Correct 173 ms 20300 KB Output is correct
30 Correct 206 ms 22348 KB Output is correct
31 Correct 244 ms 22348 KB Output is correct
32 Correct 235 ms 22348 KB Output is correct
33 Correct 185 ms 21072 KB Output is correct
34 Correct 221 ms 21324 KB Output is correct
35 Correct 228 ms 21588 KB Output is correct
36 Correct 118 ms 20304 KB Output is correct
37 Correct 231 ms 22348 KB Output is correct
38 Correct 185 ms 20280 KB Output is correct
39 Correct 241 ms 21324 KB Output is correct
40 Correct 252 ms 21324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 1 ms 4436 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4580 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
11 Correct 49 ms 23116 KB Output is correct
12 Correct 52 ms 23116 KB Output is correct
13 Incorrect 55 ms 23200 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 1 ms 4436 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4580 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
11 Correct 185 ms 19348 KB Output is correct
12 Correct 199 ms 19020 KB Output is correct
13 Correct 200 ms 18256 KB Output is correct
14 Correct 197 ms 18148 KB Output is correct
15 Correct 222 ms 19276 KB Output is correct
16 Correct 206 ms 18516 KB Output is correct
17 Correct 208 ms 18284 KB Output is correct
18 Correct 138 ms 20300 KB Output is correct
19 Correct 151 ms 17228 KB Output is correct
20 Correct 191 ms 19020 KB Output is correct
21 Correct 187 ms 22168 KB Output is correct
22 Correct 275 ms 22348 KB Output is correct
23 Correct 242 ms 21324 KB Output is correct
24 Correct 230 ms 21180 KB Output is correct
25 Correct 229 ms 23116 KB Output is correct
26 Correct 252 ms 22000 KB Output is correct
27 Correct 252 ms 21580 KB Output is correct
28 Correct 139 ms 24140 KB Output is correct
29 Correct 173 ms 20300 KB Output is correct
30 Correct 206 ms 22348 KB Output is correct
31 Correct 244 ms 22348 KB Output is correct
32 Correct 235 ms 22348 KB Output is correct
33 Correct 185 ms 21072 KB Output is correct
34 Correct 221 ms 21324 KB Output is correct
35 Correct 228 ms 21588 KB Output is correct
36 Correct 118 ms 20304 KB Output is correct
37 Correct 231 ms 22348 KB Output is correct
38 Correct 185 ms 20280 KB Output is correct
39 Correct 241 ms 21324 KB Output is correct
40 Correct 252 ms 21324 KB Output is correct
41 Correct 49 ms 23116 KB Output is correct
42 Correct 52 ms 23116 KB Output is correct
43 Incorrect 55 ms 23200 KB Output isn't correct
44 Halted 0 ms 0 KB -