Submission #256748

# Submission time Handle Problem Language Result Execution time Memory
256748 2020-08-03T07:40:24 Z 반딧불(#5039) Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
339 ms 9848 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;

int n, q;
char arr[1048576];
char str[100];
int DP[1048576]; /// 0�� Ȯ��, 1�� 0and1
int DP2[1048576]; /// 1�� Ȯ��, 0�� 0and1

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q;
    cin >> arr;
    for(int i=0; i<(1<<n); i++){
        DP[i] = DP2[i] = arr[i] - '0';
    }
    for(int d=0; d<n; d++){
        for(int i=0; i<(1<<n); i++){
            if(i & (1<<d)) DP[i] += DP[i-(1<<d)];
            else DP2[i] += DP2[i+(1<<d)];
        }
    }

    for(int i=1; i<=q; i++){
        int one = 0;
        int zero = 0;
        int lft = 0;
        cin >> str;
        for(int j=n-1; j>=0; j--){
            char c = str[n-1-j];
            if(c=='1') one |= (1<<j);
            else if(c=='0') zero |= (1<<j);
            else lft |= (1<<j);
        }

        int ans = 0;
        if(__builtin_popcount(one) > __builtin_popcount(zero)){
            for(int x=zero; 1; x = (x-1)&zero){
                ans += DP2[one|x] * (__builtin_popcount(x) & 1 ? -1 : 1);
                if(!x) break;
            }
        }
        else{
            for(int x=one; 1; x = (x-1)&one){
                ans += DP[lft|x] * (__builtin_popcount(one ^ x) & 1 ? -1 : 1);
                if(!x) break;
            }
        }
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 203 ms 5368 KB Output is correct
12 Correct 231 ms 5268 KB Output is correct
13 Correct 239 ms 4208 KB Output is correct
14 Correct 245 ms 4344 KB Output is correct
15 Correct 221 ms 5308 KB Output is correct
16 Correct 246 ms 4768 KB Output is correct
17 Correct 256 ms 4480 KB Output is correct
18 Correct 182 ms 6264 KB Output is correct
19 Correct 256 ms 3320 KB Output is correct
20 Correct 221 ms 5000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 203 ms 5368 KB Output is correct
12 Correct 231 ms 5268 KB Output is correct
13 Correct 239 ms 4208 KB Output is correct
14 Correct 245 ms 4344 KB Output is correct
15 Correct 221 ms 5308 KB Output is correct
16 Correct 246 ms 4768 KB Output is correct
17 Correct 256 ms 4480 KB Output is correct
18 Correct 182 ms 6264 KB Output is correct
19 Correct 256 ms 3320 KB Output is correct
20 Correct 221 ms 5000 KB Output is correct
21 Correct 228 ms 5368 KB Output is correct
22 Correct 256 ms 5508 KB Output is correct
23 Correct 304 ms 4728 KB Output is correct
24 Correct 292 ms 4472 KB Output is correct
25 Correct 243 ms 6392 KB Output is correct
26 Correct 286 ms 4896 KB Output is correct
27 Correct 309 ms 4728 KB Output is correct
28 Correct 177 ms 7160 KB Output is correct
29 Correct 339 ms 3064 KB Output is correct
30 Correct 238 ms 5240 KB Output is correct
31 Correct 271 ms 5112 KB Output is correct
32 Correct 283 ms 5112 KB Output is correct
33 Correct 270 ms 3832 KB Output is correct
34 Correct 294 ms 3564 KB Output is correct
35 Correct 316 ms 4088 KB Output is correct
36 Correct 170 ms 2424 KB Output is correct
37 Correct 265 ms 4472 KB Output is correct
38 Correct 315 ms 2512 KB Output is correct
39 Correct 304 ms 3576 KB Output is correct
40 Correct 288 ms 3576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Incorrect 45 ms 9848 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 203 ms 5368 KB Output is correct
12 Correct 231 ms 5268 KB Output is correct
13 Correct 239 ms 4208 KB Output is correct
14 Correct 245 ms 4344 KB Output is correct
15 Correct 221 ms 5308 KB Output is correct
16 Correct 246 ms 4768 KB Output is correct
17 Correct 256 ms 4480 KB Output is correct
18 Correct 182 ms 6264 KB Output is correct
19 Correct 256 ms 3320 KB Output is correct
20 Correct 221 ms 5000 KB Output is correct
21 Correct 228 ms 5368 KB Output is correct
22 Correct 256 ms 5508 KB Output is correct
23 Correct 304 ms 4728 KB Output is correct
24 Correct 292 ms 4472 KB Output is correct
25 Correct 243 ms 6392 KB Output is correct
26 Correct 286 ms 4896 KB Output is correct
27 Correct 309 ms 4728 KB Output is correct
28 Correct 177 ms 7160 KB Output is correct
29 Correct 339 ms 3064 KB Output is correct
30 Correct 238 ms 5240 KB Output is correct
31 Correct 271 ms 5112 KB Output is correct
32 Correct 283 ms 5112 KB Output is correct
33 Correct 270 ms 3832 KB Output is correct
34 Correct 294 ms 3564 KB Output is correct
35 Correct 316 ms 4088 KB Output is correct
36 Correct 170 ms 2424 KB Output is correct
37 Correct 265 ms 4472 KB Output is correct
38 Correct 315 ms 2512 KB Output is correct
39 Correct 304 ms 3576 KB Output is correct
40 Correct 288 ms 3576 KB Output is correct
41 Incorrect 45 ms 9848 KB Output isn't correct
42 Halted 0 ms 0 KB -