답안 #699110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699110 2023-02-15T15:52:07 Z Jarif_Rahman Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
911 ms 42184 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int L, Q; cin >> L >> Q;
    int* v = new int[1<<L];
    for(int i = 0; i < (1<<L); i++){
        char c; cin >> c;
        v[i] = c-'0';
    }

    int *dp1 = new int[1<<L], *dp2 = new int[1<<L];
    fill(dp1, dp1+(1<<L), 0);
    fill(dp2, dp2+(1<<L), 0);

    for(int i = 0; i < (1<<L); i++){
        dp1[i]+=v[i];
        dp2[((1<<L)-1)^i]+=v[i];
    }

    for(int j = 0; j < L; j++) for(int i = 0; i < (1<<L); i++) if(i&(1<<j)){
        dp1[i]+=dp1[i^(1<<j)];
        dp2[i]+=dp2[i^(1<<j)];
    }

    int L_3 = L/3;

    while(Q--){
        str s; cin >> s;
        int z = 0, o = 0, u = 0;
        reverse(s.begin(), s.end());
        for(int i = 0; i < L; i++){
            if(s[i] == '0') z+=(1<<i);
            if(s[i] == '1') o+=(1<<i);
            if(s[i] == '?') u+=(1<<i);
        }

        int ans = 0;

        if(__builtin_popcount(u) <= L_3){
            ans+=v[o];
            for(int i = u; i > 0; i = (i-1)&u) ans+=v[i|o];
        }
        else if(__builtin_popcount(o) <= L_3){
            ans+=dp1[u]*(__builtin_popcount(o)&1?-1:1);
            for(int i = o; i > 0; i = (i-1)&o)
                ans+=dp1[i|u]*((__builtin_popcount(o)-__builtin_popcount(i))&1?-1:1);
        }
        else{
            ans+=dp2[u]*(__builtin_popcount(z)&1?-1:1);
            for(int i = z; i > 0; i = (i-1)&z)
                ans+=dp2[i|u]*((__builtin_popcount(z)-__builtin_popcount(i))&1?-1:1);
        }

        cout << ans << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 204 ms 15156 KB Output is correct
12 Correct 216 ms 14668 KB Output is correct
13 Correct 228 ms 14068 KB Output is correct
14 Correct 226 ms 13968 KB Output is correct
15 Correct 218 ms 15052 KB Output is correct
16 Correct 236 ms 14180 KB Output is correct
17 Correct 238 ms 14108 KB Output is correct
18 Correct 172 ms 16076 KB Output is correct
19 Correct 192 ms 13016 KB Output is correct
20 Correct 215 ms 14656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 204 ms 15156 KB Output is correct
12 Correct 216 ms 14668 KB Output is correct
13 Correct 228 ms 14068 KB Output is correct
14 Correct 226 ms 13968 KB Output is correct
15 Correct 218 ms 15052 KB Output is correct
16 Correct 236 ms 14180 KB Output is correct
17 Correct 238 ms 14108 KB Output is correct
18 Correct 172 ms 16076 KB Output is correct
19 Correct 192 ms 13016 KB Output is correct
20 Correct 215 ms 14656 KB Output is correct
21 Correct 225 ms 17992 KB Output is correct
22 Correct 236 ms 18212 KB Output is correct
23 Correct 290 ms 17248 KB Output is correct
24 Correct 254 ms 17064 KB Output is correct
25 Correct 265 ms 18984 KB Output is correct
26 Correct 282 ms 17484 KB Output is correct
27 Correct 277 ms 17492 KB Output is correct
28 Correct 187 ms 20036 KB Output is correct
29 Correct 239 ms 16068 KB Output is correct
30 Correct 240 ms 18292 KB Output is correct
31 Correct 294 ms 18048 KB Output is correct
32 Correct 307 ms 18000 KB Output is correct
33 Correct 227 ms 16932 KB Output is correct
34 Correct 261 ms 17116 KB Output is correct
35 Correct 303 ms 17432 KB Output is correct
36 Correct 166 ms 16016 KB Output is correct
37 Correct 228 ms 18044 KB Output is correct
38 Correct 216 ms 16096 KB Output is correct
39 Correct 277 ms 17188 KB Output is correct
40 Correct 261 ms 16984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 57 ms 14924 KB Output is correct
12 Correct 60 ms 14936 KB Output is correct
13 Correct 62 ms 14812 KB Output is correct
14 Correct 80 ms 14776 KB Output is correct
15 Correct 64 ms 14924 KB Output is correct
16 Correct 77 ms 14892 KB Output is correct
17 Correct 74 ms 14848 KB Output is correct
18 Correct 49 ms 15044 KB Output is correct
19 Correct 61 ms 14824 KB Output is correct
20 Correct 72 ms 14820 KB Output is correct
21 Correct 60 ms 14920 KB Output is correct
22 Correct 68 ms 14784 KB Output is correct
23 Correct 56 ms 14792 KB Output is correct
24 Correct 62 ms 14792 KB Output is correct
25 Correct 80 ms 14908 KB Output is correct
26 Correct 51 ms 14668 KB Output is correct
27 Correct 56 ms 14932 KB Output is correct
28 Correct 57 ms 14724 KB Output is correct
29 Correct 68 ms 14808 KB Output is correct
30 Correct 70 ms 14824 KB Output is correct
31 Correct 58 ms 14848 KB Output is correct
32 Correct 73 ms 14932 KB Output is correct
33 Correct 72 ms 14872 KB Output is correct
34 Correct 51 ms 14708 KB Output is correct
35 Correct 74 ms 14796 KB Output is correct
36 Correct 68 ms 14792 KB Output is correct
37 Correct 65 ms 14800 KB Output is correct
38 Correct 66 ms 14792 KB Output is correct
39 Correct 73 ms 14796 KB Output is correct
40 Correct 85 ms 14872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 204 ms 15156 KB Output is correct
12 Correct 216 ms 14668 KB Output is correct
13 Correct 228 ms 14068 KB Output is correct
14 Correct 226 ms 13968 KB Output is correct
15 Correct 218 ms 15052 KB Output is correct
16 Correct 236 ms 14180 KB Output is correct
17 Correct 238 ms 14108 KB Output is correct
18 Correct 172 ms 16076 KB Output is correct
19 Correct 192 ms 13016 KB Output is correct
20 Correct 215 ms 14656 KB Output is correct
21 Correct 225 ms 17992 KB Output is correct
22 Correct 236 ms 18212 KB Output is correct
23 Correct 290 ms 17248 KB Output is correct
24 Correct 254 ms 17064 KB Output is correct
25 Correct 265 ms 18984 KB Output is correct
26 Correct 282 ms 17484 KB Output is correct
27 Correct 277 ms 17492 KB Output is correct
28 Correct 187 ms 20036 KB Output is correct
29 Correct 239 ms 16068 KB Output is correct
30 Correct 240 ms 18292 KB Output is correct
31 Correct 294 ms 18048 KB Output is correct
32 Correct 307 ms 18000 KB Output is correct
33 Correct 227 ms 16932 KB Output is correct
34 Correct 261 ms 17116 KB Output is correct
35 Correct 303 ms 17432 KB Output is correct
36 Correct 166 ms 16016 KB Output is correct
37 Correct 228 ms 18044 KB Output is correct
38 Correct 216 ms 16096 KB Output is correct
39 Correct 277 ms 17188 KB Output is correct
40 Correct 261 ms 16984 KB Output is correct
41 Correct 57 ms 14924 KB Output is correct
42 Correct 60 ms 14936 KB Output is correct
43 Correct 62 ms 14812 KB Output is correct
44 Correct 80 ms 14776 KB Output is correct
45 Correct 64 ms 14924 KB Output is correct
46 Correct 77 ms 14892 KB Output is correct
47 Correct 74 ms 14848 KB Output is correct
48 Correct 49 ms 15044 KB Output is correct
49 Correct 61 ms 14824 KB Output is correct
50 Correct 72 ms 14820 KB Output is correct
51 Correct 60 ms 14920 KB Output is correct
52 Correct 68 ms 14784 KB Output is correct
53 Correct 56 ms 14792 KB Output is correct
54 Correct 62 ms 14792 KB Output is correct
55 Correct 80 ms 14908 KB Output is correct
56 Correct 51 ms 14668 KB Output is correct
57 Correct 56 ms 14932 KB Output is correct
58 Correct 57 ms 14724 KB Output is correct
59 Correct 68 ms 14808 KB Output is correct
60 Correct 70 ms 14824 KB Output is correct
61 Correct 58 ms 14848 KB Output is correct
62 Correct 73 ms 14932 KB Output is correct
63 Correct 72 ms 14872 KB Output is correct
64 Correct 51 ms 14708 KB Output is correct
65 Correct 74 ms 14796 KB Output is correct
66 Correct 68 ms 14792 KB Output is correct
67 Correct 65 ms 14800 KB Output is correct
68 Correct 66 ms 14792 KB Output is correct
69 Correct 73 ms 14796 KB Output is correct
70 Correct 85 ms 14872 KB Output is correct
71 Correct 396 ms 39136 KB Output is correct
72 Correct 396 ms 39220 KB Output is correct
73 Correct 463 ms 37852 KB Output is correct
74 Correct 702 ms 38096 KB Output is correct
75 Correct 416 ms 40192 KB Output is correct
76 Correct 911 ms 38512 KB Output is correct
77 Correct 720 ms 38436 KB Output is correct
78 Correct 279 ms 42184 KB Output is correct
79 Correct 402 ms 36164 KB Output is correct
80 Correct 392 ms 39244 KB Output is correct
81 Correct 529 ms 39188 KB Output is correct
82 Correct 756 ms 38284 KB Output is correct
83 Correct 387 ms 37312 KB Output is correct
84 Correct 559 ms 38200 KB Output is correct
85 Correct 750 ms 38368 KB Output is correct
86 Correct 244 ms 36116 KB Output is correct
87 Correct 403 ms 39080 KB Output is correct
88 Correct 402 ms 36280 KB Output is correct
89 Correct 453 ms 37848 KB Output is correct
90 Correct 604 ms 38136 KB Output is correct
91 Correct 441 ms 37276 KB Output is correct
92 Correct 851 ms 38392 KB Output is correct
93 Correct 711 ms 38276 KB Output is correct
94 Correct 277 ms 36176 KB Output is correct
95 Correct 637 ms 38296 KB Output is correct
96 Correct 628 ms 38280 KB Output is correct
97 Correct 624 ms 38184 KB Output is correct
98 Correct 618 ms 38260 KB Output is correct
99 Correct 661 ms 38248 KB Output is correct
100 Correct 648 ms 38232 KB Output is correct