답안 #256752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256752 2020-08-03T07:41:45 Z 반딧불(#5039) Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 39116 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[1048579];
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';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 216 ms 5368 KB Output is correct
12 Correct 222 ms 5040 KB Output is correct
13 Correct 232 ms 4216 KB Output is correct
14 Correct 259 ms 4472 KB Output is correct
15 Correct 214 ms 5368 KB Output is correct
16 Correct 251 ms 4472 KB Output is correct
17 Correct 257 ms 4600 KB Output is correct
18 Correct 161 ms 6392 KB Output is correct
19 Correct 254 ms 3448 KB Output is correct
20 Correct 208 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 216 ms 5368 KB Output is correct
12 Correct 222 ms 5040 KB Output is correct
13 Correct 232 ms 4216 KB Output is correct
14 Correct 259 ms 4472 KB Output is correct
15 Correct 214 ms 5368 KB Output is correct
16 Correct 251 ms 4472 KB Output is correct
17 Correct 257 ms 4600 KB Output is correct
18 Correct 161 ms 6392 KB Output is correct
19 Correct 254 ms 3448 KB Output is correct
20 Correct 208 ms 4984 KB Output is correct
21 Correct 228 ms 5372 KB Output is correct
22 Correct 245 ms 5496 KB Output is correct
23 Correct 297 ms 4600 KB Output is correct
24 Correct 293 ms 4344 KB Output is correct
25 Correct 244 ms 6440 KB Output is correct
26 Correct 295 ms 4984 KB Output is correct
27 Correct 309 ms 4856 KB Output is correct
28 Correct 190 ms 7416 KB Output is correct
29 Correct 336 ms 3576 KB Output is correct
30 Correct 239 ms 5788 KB Output is correct
31 Correct 267 ms 5368 KB Output is correct
32 Correct 286 ms 5468 KB Output is correct
33 Correct 270 ms 4344 KB Output is correct
34 Correct 299 ms 4216 KB Output is correct
35 Correct 312 ms 4472 KB Output is correct
36 Correct 168 ms 3064 KB Output is correct
37 Correct 272 ms 4984 KB Output is correct
38 Correct 322 ms 3192 KB Output is correct
39 Correct 310 ms 4344 KB Output is correct
40 Correct 288 ms 4016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 10360 KB Output is correct
12 Correct 47 ms 10436 KB Output is correct
13 Correct 51 ms 10360 KB Output is correct
14 Correct 53 ms 10360 KB Output is correct
15 Correct 43 ms 10488 KB Output is correct
16 Correct 72 ms 10360 KB Output is correct
17 Correct 62 ms 10364 KB Output is correct
18 Correct 40 ms 10620 KB Output is correct
19 Correct 155 ms 10232 KB Output is correct
20 Correct 43 ms 10360 KB Output is correct
21 Correct 53 ms 10412 KB Output is correct
22 Correct 52 ms 10360 KB Output is correct
23 Correct 52 ms 10360 KB Output is correct
24 Correct 63 ms 10360 KB Output is correct
25 Correct 61 ms 10360 KB Output is correct
26 Correct 36 ms 10236 KB Output is correct
27 Correct 42 ms 10360 KB Output is correct
28 Correct 93 ms 10232 KB Output is correct
29 Correct 52 ms 10360 KB Output is correct
30 Correct 60 ms 10360 KB Output is correct
31 Correct 48 ms 10360 KB Output is correct
32 Correct 58 ms 10360 KB Output is correct
33 Correct 64 ms 10360 KB Output is correct
34 Correct 37 ms 10232 KB Output is correct
35 Correct 62 ms 10360 KB Output is correct
36 Correct 63 ms 10488 KB Output is correct
37 Correct 61 ms 10360 KB Output is correct
38 Correct 68 ms 10360 KB Output is correct
39 Correct 65 ms 10360 KB Output is correct
40 Correct 72 ms 10384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 216 ms 5368 KB Output is correct
12 Correct 222 ms 5040 KB Output is correct
13 Correct 232 ms 4216 KB Output is correct
14 Correct 259 ms 4472 KB Output is correct
15 Correct 214 ms 5368 KB Output is correct
16 Correct 251 ms 4472 KB Output is correct
17 Correct 257 ms 4600 KB Output is correct
18 Correct 161 ms 6392 KB Output is correct
19 Correct 254 ms 3448 KB Output is correct
20 Correct 208 ms 4984 KB Output is correct
21 Correct 228 ms 5372 KB Output is correct
22 Correct 245 ms 5496 KB Output is correct
23 Correct 297 ms 4600 KB Output is correct
24 Correct 293 ms 4344 KB Output is correct
25 Correct 244 ms 6440 KB Output is correct
26 Correct 295 ms 4984 KB Output is correct
27 Correct 309 ms 4856 KB Output is correct
28 Correct 190 ms 7416 KB Output is correct
29 Correct 336 ms 3576 KB Output is correct
30 Correct 239 ms 5788 KB Output is correct
31 Correct 267 ms 5368 KB Output is correct
32 Correct 286 ms 5468 KB Output is correct
33 Correct 270 ms 4344 KB Output is correct
34 Correct 299 ms 4216 KB Output is correct
35 Correct 312 ms 4472 KB Output is correct
36 Correct 168 ms 3064 KB Output is correct
37 Correct 272 ms 4984 KB Output is correct
38 Correct 322 ms 3192 KB Output is correct
39 Correct 310 ms 4344 KB Output is correct
40 Correct 288 ms 4016 KB Output is correct
41 Correct 45 ms 10360 KB Output is correct
42 Correct 47 ms 10436 KB Output is correct
43 Correct 51 ms 10360 KB Output is correct
44 Correct 53 ms 10360 KB Output is correct
45 Correct 43 ms 10488 KB Output is correct
46 Correct 72 ms 10360 KB Output is correct
47 Correct 62 ms 10364 KB Output is correct
48 Correct 40 ms 10620 KB Output is correct
49 Correct 155 ms 10232 KB Output is correct
50 Correct 43 ms 10360 KB Output is correct
51 Correct 53 ms 10412 KB Output is correct
52 Correct 52 ms 10360 KB Output is correct
53 Correct 52 ms 10360 KB Output is correct
54 Correct 63 ms 10360 KB Output is correct
55 Correct 61 ms 10360 KB Output is correct
56 Correct 36 ms 10236 KB Output is correct
57 Correct 42 ms 10360 KB Output is correct
58 Correct 93 ms 10232 KB Output is correct
59 Correct 52 ms 10360 KB Output is correct
60 Correct 60 ms 10360 KB Output is correct
61 Correct 48 ms 10360 KB Output is correct
62 Correct 58 ms 10360 KB Output is correct
63 Correct 64 ms 10360 KB Output is correct
64 Correct 37 ms 10232 KB Output is correct
65 Correct 62 ms 10360 KB Output is correct
66 Correct 63 ms 10488 KB Output is correct
67 Correct 61 ms 10360 KB Output is correct
68 Correct 68 ms 10360 KB Output is correct
69 Correct 65 ms 10360 KB Output is correct
70 Correct 72 ms 10384 KB Output is correct
71 Correct 321 ms 14712 KB Output is correct
72 Correct 362 ms 14840 KB Output is correct
73 Correct 505 ms 13432 KB Output is correct
74 Correct 512 ms 13800 KB Output is correct
75 Correct 331 ms 15736 KB Output is correct
76 Correct 730 ms 14840 KB Output is correct
77 Correct 758 ms 35448 KB Output is correct
78 Correct 237 ms 39116 KB Output is correct
79 Execution timed out 2084 ms 28628 KB Time limit exceeded
80 Halted 0 ms 0 KB -