답안 #256739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256739 2020-08-03T07:34:39 Z 반딧불(#5039) Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 40380 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, q;
int arr[1048576];
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);
             ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 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 392 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 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 392 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 770 ms 4668 KB Output is correct
12 Correct 779 ms 4472 KB Output is correct
13 Correct 814 ms 3824 KB Output is correct
14 Correct 829 ms 3708 KB Output is correct
15 Correct 786 ms 4716 KB Output is correct
16 Correct 844 ms 3908 KB Output is correct
17 Correct 835 ms 3960 KB Output is correct
18 Correct 782 ms 5752 KB Output is correct
19 Correct 918 ms 2832 KB Output is correct
20 Correct 777 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 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 392 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 770 ms 4668 KB Output is correct
12 Correct 779 ms 4472 KB Output is correct
13 Correct 814 ms 3824 KB Output is correct
14 Correct 829 ms 3708 KB Output is correct
15 Correct 786 ms 4716 KB Output is correct
16 Correct 844 ms 3908 KB Output is correct
17 Correct 835 ms 3960 KB Output is correct
18 Correct 782 ms 5752 KB Output is correct
19 Correct 918 ms 2832 KB Output is correct
20 Correct 777 ms 4344 KB Output is correct
21 Correct 959 ms 4904 KB Output is correct
22 Correct 987 ms 5076 KB Output is correct
23 Correct 1052 ms 4216 KB Output is correct
24 Correct 1052 ms 4116 KB Output is correct
25 Correct 1002 ms 5968 KB Output is correct
26 Correct 1061 ms 4476 KB Output is correct
27 Correct 1054 ms 4216 KB Output is correct
28 Correct 934 ms 6948 KB Output is correct
29 Correct 1187 ms 2924 KB Output is correct
30 Correct 965 ms 4984 KB Output is correct
31 Correct 1055 ms 4808 KB Output is correct
32 Correct 1080 ms 4848 KB Output is correct
33 Correct 1027 ms 3960 KB Output is correct
34 Correct 1046 ms 3832 KB Output is correct
35 Correct 1077 ms 4340 KB Output is correct
36 Correct 976 ms 2808 KB Output is correct
37 Correct 994 ms 4820 KB Output is correct
38 Correct 1113 ms 2964 KB Output is correct
39 Correct 1068 ms 4108 KB Output is correct
40 Correct 1081 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 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 392 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 204 ms 14876 KB Output is correct
12 Correct 209 ms 14968 KB Output is correct
13 Correct 227 ms 14840 KB Output is correct
14 Correct 230 ms 14832 KB Output is correct
15 Correct 206 ms 14996 KB Output is correct
16 Correct 233 ms 14840 KB Output is correct
17 Correct 243 ms 14976 KB Output is correct
18 Correct 211 ms 15096 KB Output is correct
19 Correct 435 ms 14928 KB Output is correct
20 Correct 204 ms 14884 KB Output is correct
21 Correct 229 ms 14968 KB Output is correct
22 Correct 233 ms 14840 KB Output is correct
23 Correct 210 ms 14968 KB Output is correct
24 Correct 232 ms 14840 KB Output is correct
25 Correct 277 ms 14968 KB Output is correct
26 Correct 199 ms 14840 KB Output is correct
27 Correct 208 ms 14968 KB Output is correct
28 Correct 297 ms 14840 KB Output is correct
29 Correct 222 ms 14840 KB Output is correct
30 Correct 240 ms 14968 KB Output is correct
31 Correct 207 ms 14840 KB Output is correct
32 Correct 240 ms 14892 KB Output is correct
33 Correct 253 ms 14968 KB Output is correct
34 Correct 204 ms 14840 KB Output is correct
35 Correct 240 ms 14832 KB Output is correct
36 Correct 242 ms 14968 KB Output is correct
37 Correct 250 ms 14840 KB Output is correct
38 Correct 235 ms 14968 KB Output is correct
39 Correct 238 ms 14968 KB Output is correct
40 Correct 251 ms 14968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 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 392 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 770 ms 4668 KB Output is correct
12 Correct 779 ms 4472 KB Output is correct
13 Correct 814 ms 3824 KB Output is correct
14 Correct 829 ms 3708 KB Output is correct
15 Correct 786 ms 4716 KB Output is correct
16 Correct 844 ms 3908 KB Output is correct
17 Correct 835 ms 3960 KB Output is correct
18 Correct 782 ms 5752 KB Output is correct
19 Correct 918 ms 2832 KB Output is correct
20 Correct 777 ms 4344 KB Output is correct
21 Correct 959 ms 4904 KB Output is correct
22 Correct 987 ms 5076 KB Output is correct
23 Correct 1052 ms 4216 KB Output is correct
24 Correct 1052 ms 4116 KB Output is correct
25 Correct 1002 ms 5968 KB Output is correct
26 Correct 1061 ms 4476 KB Output is correct
27 Correct 1054 ms 4216 KB Output is correct
28 Correct 934 ms 6948 KB Output is correct
29 Correct 1187 ms 2924 KB Output is correct
30 Correct 965 ms 4984 KB Output is correct
31 Correct 1055 ms 4808 KB Output is correct
32 Correct 1080 ms 4848 KB Output is correct
33 Correct 1027 ms 3960 KB Output is correct
34 Correct 1046 ms 3832 KB Output is correct
35 Correct 1077 ms 4340 KB Output is correct
36 Correct 976 ms 2808 KB Output is correct
37 Correct 994 ms 4820 KB Output is correct
38 Correct 1113 ms 2964 KB Output is correct
39 Correct 1068 ms 4108 KB Output is correct
40 Correct 1081 ms 3932 KB Output is correct
41 Correct 204 ms 14876 KB Output is correct
42 Correct 209 ms 14968 KB Output is correct
43 Correct 227 ms 14840 KB Output is correct
44 Correct 230 ms 14832 KB Output is correct
45 Correct 206 ms 14996 KB Output is correct
46 Correct 233 ms 14840 KB Output is correct
47 Correct 243 ms 14976 KB Output is correct
48 Correct 211 ms 15096 KB Output is correct
49 Correct 435 ms 14928 KB Output is correct
50 Correct 204 ms 14884 KB Output is correct
51 Correct 229 ms 14968 KB Output is correct
52 Correct 233 ms 14840 KB Output is correct
53 Correct 210 ms 14968 KB Output is correct
54 Correct 232 ms 14840 KB Output is correct
55 Correct 277 ms 14968 KB Output is correct
56 Correct 199 ms 14840 KB Output is correct
57 Correct 208 ms 14968 KB Output is correct
58 Correct 297 ms 14840 KB Output is correct
59 Correct 222 ms 14840 KB Output is correct
60 Correct 240 ms 14968 KB Output is correct
61 Correct 207 ms 14840 KB Output is correct
62 Correct 240 ms 14892 KB Output is correct
63 Correct 253 ms 14968 KB Output is correct
64 Correct 204 ms 14840 KB Output is correct
65 Correct 240 ms 14832 KB Output is correct
66 Correct 242 ms 14968 KB Output is correct
67 Correct 250 ms 14840 KB Output is correct
68 Correct 235 ms 14968 KB Output is correct
69 Correct 238 ms 14968 KB Output is correct
70 Correct 251 ms 14968 KB Output is correct
71 Correct 1663 ms 39212 KB Output is correct
72 Correct 1647 ms 39416 KB Output is correct
73 Correct 1913 ms 37980 KB Output is correct
74 Correct 1983 ms 38320 KB Output is correct
75 Correct 1642 ms 40380 KB Output is correct
76 Execution timed out 2074 ms 36208 KB Time limit exceeded
77 Halted 0 ms 0 KB -