Submission #256735

# Submission time Handle Problem Language Result Execution time Memory
256735 2020-08-03T07:32:43 Z 반딧불(#5039) Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
1196 ms 7256 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int main(){
    scanf("%d %d", &n, &q);
    for(int i=0; i<(1<<n); i++){
        scanf("%1d", &arr[i]);
        DP[i] = DP2[i] = arr[i];
    }
    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;
        for(int j=n-1; j>=0; j--){
            char c;
            scanf(" %c", &c);
            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;
            }
        }
        printf("%d\n", ans);
    }
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
snake_escaping.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%1d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~~
snake_escaping.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c", &c);
             ~~~~~^~~~~~~~~~~
# 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 2 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 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 779 ms 5112 KB Output is correct
12 Correct 787 ms 5112 KB Output is correct
13 Correct 814 ms 4472 KB Output is correct
14 Correct 825 ms 4344 KB Output is correct
15 Correct 811 ms 5352 KB Output is correct
16 Correct 833 ms 4600 KB Output is correct
17 Correct 826 ms 4472 KB Output is correct
18 Correct 742 ms 6264 KB Output is correct
19 Correct 892 ms 3192 KB Output is correct
20 Correct 766 ms 4948 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 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 779 ms 5112 KB Output is correct
12 Correct 787 ms 5112 KB Output is correct
13 Correct 814 ms 4472 KB Output is correct
14 Correct 825 ms 4344 KB Output is correct
15 Correct 811 ms 5352 KB Output is correct
16 Correct 833 ms 4600 KB Output is correct
17 Correct 826 ms 4472 KB Output is correct
18 Correct 742 ms 6264 KB Output is correct
19 Correct 892 ms 3192 KB Output is correct
20 Correct 766 ms 4948 KB Output is correct
21 Correct 975 ms 5328 KB Output is correct
22 Correct 1008 ms 5368 KB Output is correct
23 Correct 1057 ms 4464 KB Output is correct
24 Correct 1075 ms 4344 KB Output is correct
25 Correct 998 ms 6376 KB Output is correct
26 Correct 1055 ms 4880 KB Output is correct
27 Correct 1050 ms 4856 KB Output is correct
28 Correct 943 ms 7256 KB Output is correct
29 Correct 1175 ms 3412 KB Output is correct
30 Correct 981 ms 5660 KB Output is correct
31 Correct 1004 ms 5364 KB Output is correct
32 Correct 1062 ms 5448 KB Output is correct
33 Correct 1006 ms 4344 KB Output is correct
34 Correct 1064 ms 4420 KB Output is correct
35 Correct 1087 ms 4744 KB Output is correct
36 Correct 1037 ms 3256 KB Output is correct
37 Correct 1196 ms 5240 KB Output is correct
38 Correct 1101 ms 3448 KB Output is correct
39 Correct 1065 ms 4468 KB Output is correct
40 Correct 1071 ms 4264 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 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Incorrect 13 ms 1792 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 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 779 ms 5112 KB Output is correct
12 Correct 787 ms 5112 KB Output is correct
13 Correct 814 ms 4472 KB Output is correct
14 Correct 825 ms 4344 KB Output is correct
15 Correct 811 ms 5352 KB Output is correct
16 Correct 833 ms 4600 KB Output is correct
17 Correct 826 ms 4472 KB Output is correct
18 Correct 742 ms 6264 KB Output is correct
19 Correct 892 ms 3192 KB Output is correct
20 Correct 766 ms 4948 KB Output is correct
21 Correct 975 ms 5328 KB Output is correct
22 Correct 1008 ms 5368 KB Output is correct
23 Correct 1057 ms 4464 KB Output is correct
24 Correct 1075 ms 4344 KB Output is correct
25 Correct 998 ms 6376 KB Output is correct
26 Correct 1055 ms 4880 KB Output is correct
27 Correct 1050 ms 4856 KB Output is correct
28 Correct 943 ms 7256 KB Output is correct
29 Correct 1175 ms 3412 KB Output is correct
30 Correct 981 ms 5660 KB Output is correct
31 Correct 1004 ms 5364 KB Output is correct
32 Correct 1062 ms 5448 KB Output is correct
33 Correct 1006 ms 4344 KB Output is correct
34 Correct 1064 ms 4420 KB Output is correct
35 Correct 1087 ms 4744 KB Output is correct
36 Correct 1037 ms 3256 KB Output is correct
37 Correct 1196 ms 5240 KB Output is correct
38 Correct 1101 ms 3448 KB Output is correct
39 Correct 1065 ms 4468 KB Output is correct
40 Correct 1071 ms 4264 KB Output is correct
41 Incorrect 13 ms 1792 KB Output isn't correct
42 Halted 0 ms 0 KB -