Submission #256785

# Submission time Handle Problem Language Result Execution time Memory
256785 2020-08-03T08:01:14 Z 반딧불(#5039) Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 18296 KB
#include <iostream>

using namespace std;

typedef long long ll;

int n, q;
char arr[1048579];
char str[100], c;
int DP[1<<20]; /// 0�� Ȯ��, 1�� 0and1
int DP2[1<<20]; /// 1�� Ȯ��, 0�� 0and1
int one, zero, lft;
int ans;

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

        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 232 ms 4472 KB Output is correct
12 Correct 257 ms 4100 KB Output is correct
13 Correct 278 ms 3448 KB Output is correct
14 Correct 284 ms 3448 KB Output is correct
15 Correct 245 ms 4344 KB Output is correct
16 Correct 278 ms 3576 KB Output is correct
17 Correct 293 ms 3568 KB Output is correct
18 Correct 189 ms 5368 KB Output is correct
19 Correct 353 ms 2424 KB Output is correct
20 Correct 244 ms 4088 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 232 ms 4472 KB Output is correct
12 Correct 257 ms 4100 KB Output is correct
13 Correct 278 ms 3448 KB Output is correct
14 Correct 284 ms 3448 KB Output is correct
15 Correct 245 ms 4344 KB Output is correct
16 Correct 278 ms 3576 KB Output is correct
17 Correct 293 ms 3568 KB Output is correct
18 Correct 189 ms 5368 KB Output is correct
19 Correct 353 ms 2424 KB Output is correct
20 Correct 244 ms 4088 KB Output is correct
21 Correct 278 ms 4472 KB Output is correct
22 Correct 278 ms 4616 KB Output is correct
23 Correct 347 ms 3580 KB Output is correct
24 Correct 345 ms 3448 KB Output is correct
25 Correct 277 ms 5428 KB Output is correct
26 Correct 341 ms 3960 KB Output is correct
27 Correct 346 ms 3832 KB Output is correct
28 Correct 189 ms 6392 KB Output is correct
29 Correct 464 ms 2436 KB Output is correct
30 Correct 249 ms 4600 KB Output is correct
31 Correct 316 ms 4472 KB Output is correct
32 Correct 359 ms 4516 KB Output is correct
33 Correct 310 ms 3448 KB Output is correct
34 Correct 347 ms 3448 KB Output is correct
35 Correct 350 ms 4000 KB Output is correct
36 Correct 177 ms 2424 KB Output is correct
37 Correct 261 ms 4592 KB Output is correct
38 Correct 414 ms 2424 KB Output is correct
39 Correct 358 ms 3704 KB Output is correct
40 Correct 353 ms 3584 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 45 ms 9832 KB Output is correct
12 Correct 54 ms 9848 KB Output is correct
13 Correct 66 ms 9720 KB Output is correct
14 Correct 64 ms 9848 KB Output is correct
15 Correct 47 ms 9916 KB Output is correct
16 Correct 82 ms 9812 KB Output is correct
17 Correct 75 ms 9720 KB Output is correct
18 Correct 40 ms 9976 KB Output is correct
19 Correct 256 ms 9720 KB Output is correct
20 Correct 50 ms 9976 KB Output is correct
21 Correct 55 ms 9848 KB Output is correct
22 Correct 74 ms 9848 KB Output is correct
23 Correct 56 ms 9752 KB Output is correct
24 Correct 103 ms 9720 KB Output is correct
25 Correct 83 ms 9720 KB Output is correct
26 Correct 40 ms 9720 KB Output is correct
27 Correct 47 ms 9848 KB Output is correct
28 Correct 143 ms 9720 KB Output is correct
29 Correct 64 ms 9724 KB Output is correct
30 Correct 106 ms 9720 KB Output is correct
31 Correct 50 ms 9720 KB Output is correct
32 Correct 67 ms 9720 KB Output is correct
33 Correct 97 ms 9848 KB Output is correct
34 Correct 40 ms 9728 KB Output is correct
35 Correct 83 ms 9720 KB Output is correct
36 Correct 86 ms 9720 KB Output is correct
37 Correct 164 ms 9720 KB Output is correct
38 Correct 171 ms 9720 KB Output is correct
39 Correct 112 ms 9720 KB Output is correct
40 Correct 80 ms 9720 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 232 ms 4472 KB Output is correct
12 Correct 257 ms 4100 KB Output is correct
13 Correct 278 ms 3448 KB Output is correct
14 Correct 284 ms 3448 KB Output is correct
15 Correct 245 ms 4344 KB Output is correct
16 Correct 278 ms 3576 KB Output is correct
17 Correct 293 ms 3568 KB Output is correct
18 Correct 189 ms 5368 KB Output is correct
19 Correct 353 ms 2424 KB Output is correct
20 Correct 244 ms 4088 KB Output is correct
21 Correct 278 ms 4472 KB Output is correct
22 Correct 278 ms 4616 KB Output is correct
23 Correct 347 ms 3580 KB Output is correct
24 Correct 345 ms 3448 KB Output is correct
25 Correct 277 ms 5428 KB Output is correct
26 Correct 341 ms 3960 KB Output is correct
27 Correct 346 ms 3832 KB Output is correct
28 Correct 189 ms 6392 KB Output is correct
29 Correct 464 ms 2436 KB Output is correct
30 Correct 249 ms 4600 KB Output is correct
31 Correct 316 ms 4472 KB Output is correct
32 Correct 359 ms 4516 KB Output is correct
33 Correct 310 ms 3448 KB Output is correct
34 Correct 347 ms 3448 KB Output is correct
35 Correct 350 ms 4000 KB Output is correct
36 Correct 177 ms 2424 KB Output is correct
37 Correct 261 ms 4592 KB Output is correct
38 Correct 414 ms 2424 KB Output is correct
39 Correct 358 ms 3704 KB Output is correct
40 Correct 353 ms 3584 KB Output is correct
41 Correct 45 ms 9832 KB Output is correct
42 Correct 54 ms 9848 KB Output is correct
43 Correct 66 ms 9720 KB Output is correct
44 Correct 64 ms 9848 KB Output is correct
45 Correct 47 ms 9916 KB Output is correct
46 Correct 82 ms 9812 KB Output is correct
47 Correct 75 ms 9720 KB Output is correct
48 Correct 40 ms 9976 KB Output is correct
49 Correct 256 ms 9720 KB Output is correct
50 Correct 50 ms 9976 KB Output is correct
51 Correct 55 ms 9848 KB Output is correct
52 Correct 74 ms 9848 KB Output is correct
53 Correct 56 ms 9752 KB Output is correct
54 Correct 103 ms 9720 KB Output is correct
55 Correct 83 ms 9720 KB Output is correct
56 Correct 40 ms 9720 KB Output is correct
57 Correct 47 ms 9848 KB Output is correct
58 Correct 143 ms 9720 KB Output is correct
59 Correct 64 ms 9724 KB Output is correct
60 Correct 106 ms 9720 KB Output is correct
61 Correct 50 ms 9720 KB Output is correct
62 Correct 67 ms 9720 KB Output is correct
63 Correct 97 ms 9848 KB Output is correct
64 Correct 40 ms 9728 KB Output is correct
65 Correct 83 ms 9720 KB Output is correct
66 Correct 86 ms 9720 KB Output is correct
67 Correct 164 ms 9720 KB Output is correct
68 Correct 171 ms 9720 KB Output is correct
69 Correct 112 ms 9720 KB Output is correct
70 Correct 80 ms 9720 KB Output is correct
71 Correct 344 ms 14584 KB Output is correct
72 Correct 442 ms 15540 KB Output is correct
73 Correct 626 ms 13816 KB Output is correct
74 Correct 720 ms 14328 KB Output is correct
75 Correct 377 ms 16120 KB Output is correct
76 Correct 970 ms 16220 KB Output is correct
77 Correct 1475 ms 14476 KB Output is correct
78 Correct 254 ms 18296 KB Output is correct
79 Execution timed out 2060 ms 12040 KB Time limit exceeded
80 Halted 0 ms 0 KB -