답안 #1094545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094545 2024-09-29T21:19:53 Z BLOBVISGOD Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
527 ms 43512 KB
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int L = 20;
int SOS[3][1<<L];


int main(){
    cin.tie(NULL),cin.sync_with_stdio(false);
    
    int l,q; cin >> l >> q;
    int msk_all = (1<<l)-1;
    string s; cin >> s;
    rep(i,0,1<<l){
        // ones
        SOS[1][i] = SOS[2][i] = int(s[i]-'0');
        SOS[0][msk_all^i] = int(s[i]-'0');
    }

    rep(X,0,2) rep(i,0,l) rep(mask,0,1<<l) if (mask&(1<<i)) SOS[X][mask] += SOS[X][mask^(1<<i)]; 
    
    while (q--){
        string s; cin >> s;
        reverse(all(s));
        if (count(all(s),'?') < 7){
            int qmask = 0, omask = 0;
            rep(i,0,l) {
                if (s[i] == '?') qmask |= 1<<i;
                else if (s[i] == '1') omask |= 1<<i;
            }
            int ans = 0, msk = qmask;
            while (msk){
                ans += SOS[2][msk|omask];
                msk = (msk-1)&qmask;
            } ans += SOS[2][omask];
            cout << ans << '\n';
        }else if (count(all(s),'1') < 7){
            int ans = 0, qmask = 0, omask = 0;
            rep(i,0,l) {
                if (s[i] == '?') qmask |= 1<<i;
                else if (s[i] == '1') omask |= 1<<i;
            }
            int msk = omask;
            while (msk){
                ans += (1-2*(__builtin_popcount(msk)&1))*SOS[1][msk|qmask];
                msk = (msk-1)&omask;
            } ans += SOS[1][qmask];
            cout << abs(ans) << '\n';
        }else{
            int ans = 0, qmask = 0, omask = 0;
            rep(i,0,l) {
                if (s[i] == '?') qmask |= 1<<i;
                else if (s[i] == '0') omask |= 1<<i;
            }
            int msk = omask;
            while(msk){
                ans += (1-2*(__builtin_popcount(msk)&1))*SOS[0][msk|qmask];
                msk = (msk-1)&omask;
            } ans += SOS[0][qmask];
            cout << abs(ans) << '\n';
        }
    }




    

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 472 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 472 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 164 ms 15260 KB Output is correct
12 Correct 171 ms 14672 KB Output is correct
13 Correct 150 ms 14112 KB Output is correct
14 Correct 139 ms 14256 KB Output is correct
15 Correct 185 ms 15188 KB Output is correct
16 Correct 151 ms 14424 KB Output is correct
17 Correct 148 ms 14160 KB Output is correct
18 Correct 117 ms 16212 KB Output is correct
19 Correct 105 ms 13140 KB Output is correct
20 Correct 178 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 472 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 164 ms 15260 KB Output is correct
12 Correct 171 ms 14672 KB Output is correct
13 Correct 150 ms 14112 KB Output is correct
14 Correct 139 ms 14256 KB Output is correct
15 Correct 185 ms 15188 KB Output is correct
16 Correct 151 ms 14424 KB Output is correct
17 Correct 148 ms 14160 KB Output is correct
18 Correct 117 ms 16212 KB Output is correct
19 Correct 105 ms 13140 KB Output is correct
20 Correct 178 ms 14676 KB Output is correct
21 Correct 334 ms 18304 KB Output is correct
22 Correct 187 ms 18256 KB Output is correct
23 Correct 156 ms 17320 KB Output is correct
24 Correct 153 ms 17232 KB Output is correct
25 Correct 202 ms 19284 KB Output is correct
26 Correct 183 ms 17748 KB Output is correct
27 Correct 180 ms 17748 KB Output is correct
28 Correct 124 ms 20304 KB Output is correct
29 Correct 119 ms 16200 KB Output is correct
30 Correct 248 ms 18260 KB Output is correct
31 Correct 209 ms 18260 KB Output is correct
32 Correct 181 ms 18120 KB Output is correct
33 Correct 151 ms 16980 KB Output is correct
34 Correct 163 ms 17232 KB Output is correct
35 Correct 182 ms 17744 KB Output is correct
36 Correct 117 ms 16208 KB Output is correct
37 Correct 205 ms 18260 KB Output is correct
38 Correct 115 ms 16116 KB Output is correct
39 Correct 159 ms 17236 KB Output is correct
40 Correct 156 ms 17064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 472 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 48 ms 16112 KB Output is correct
12 Correct 50 ms 16116 KB Output is correct
13 Correct 50 ms 16112 KB Output is correct
14 Correct 61 ms 15960 KB Output is correct
15 Correct 51 ms 16044 KB Output is correct
16 Correct 69 ms 16008 KB Output is correct
17 Correct 55 ms 16012 KB Output is correct
18 Correct 44 ms 16132 KB Output is correct
19 Correct 45 ms 15856 KB Output is correct
20 Correct 52 ms 16116 KB Output is correct
21 Correct 60 ms 16112 KB Output is correct
22 Correct 64 ms 15984 KB Output is correct
23 Correct 51 ms 16096 KB Output is correct
24 Correct 54 ms 16120 KB Output is correct
25 Correct 57 ms 15932 KB Output is correct
26 Correct 47 ms 15856 KB Output is correct
27 Correct 49 ms 16204 KB Output is correct
28 Correct 50 ms 15960 KB Output is correct
29 Correct 51 ms 16120 KB Output is correct
30 Correct 54 ms 15960 KB Output is correct
31 Correct 49 ms 16116 KB Output is correct
32 Correct 62 ms 16120 KB Output is correct
33 Correct 56 ms 15976 KB Output is correct
34 Correct 46 ms 15960 KB Output is correct
35 Correct 55 ms 16112 KB Output is correct
36 Correct 57 ms 15952 KB Output is correct
37 Correct 55 ms 16112 KB Output is correct
38 Correct 56 ms 16116 KB Output is correct
39 Correct 59 ms 15956 KB Output is correct
40 Correct 55 ms 16112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 472 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 164 ms 15260 KB Output is correct
12 Correct 171 ms 14672 KB Output is correct
13 Correct 150 ms 14112 KB Output is correct
14 Correct 139 ms 14256 KB Output is correct
15 Correct 185 ms 15188 KB Output is correct
16 Correct 151 ms 14424 KB Output is correct
17 Correct 148 ms 14160 KB Output is correct
18 Correct 117 ms 16212 KB Output is correct
19 Correct 105 ms 13140 KB Output is correct
20 Correct 178 ms 14676 KB Output is correct
21 Correct 334 ms 18304 KB Output is correct
22 Correct 187 ms 18256 KB Output is correct
23 Correct 156 ms 17320 KB Output is correct
24 Correct 153 ms 17232 KB Output is correct
25 Correct 202 ms 19284 KB Output is correct
26 Correct 183 ms 17748 KB Output is correct
27 Correct 180 ms 17748 KB Output is correct
28 Correct 124 ms 20304 KB Output is correct
29 Correct 119 ms 16200 KB Output is correct
30 Correct 248 ms 18260 KB Output is correct
31 Correct 209 ms 18260 KB Output is correct
32 Correct 181 ms 18120 KB Output is correct
33 Correct 151 ms 16980 KB Output is correct
34 Correct 163 ms 17232 KB Output is correct
35 Correct 182 ms 17744 KB Output is correct
36 Correct 117 ms 16208 KB Output is correct
37 Correct 205 ms 18260 KB Output is correct
38 Correct 115 ms 16116 KB Output is correct
39 Correct 159 ms 17236 KB Output is correct
40 Correct 156 ms 17064 KB Output is correct
41 Correct 48 ms 16112 KB Output is correct
42 Correct 50 ms 16116 KB Output is correct
43 Correct 50 ms 16112 KB Output is correct
44 Correct 61 ms 15960 KB Output is correct
45 Correct 51 ms 16044 KB Output is correct
46 Correct 69 ms 16008 KB Output is correct
47 Correct 55 ms 16012 KB Output is correct
48 Correct 44 ms 16132 KB Output is correct
49 Correct 45 ms 15856 KB Output is correct
50 Correct 52 ms 16116 KB Output is correct
51 Correct 60 ms 16112 KB Output is correct
52 Correct 64 ms 15984 KB Output is correct
53 Correct 51 ms 16096 KB Output is correct
54 Correct 54 ms 16120 KB Output is correct
55 Correct 57 ms 15932 KB Output is correct
56 Correct 47 ms 15856 KB Output is correct
57 Correct 49 ms 16204 KB Output is correct
58 Correct 50 ms 15960 KB Output is correct
59 Correct 51 ms 16120 KB Output is correct
60 Correct 54 ms 15960 KB Output is correct
61 Correct 49 ms 16116 KB Output is correct
62 Correct 62 ms 16120 KB Output is correct
63 Correct 56 ms 15976 KB Output is correct
64 Correct 46 ms 15960 KB Output is correct
65 Correct 55 ms 16112 KB Output is correct
66 Correct 57 ms 15952 KB Output is correct
67 Correct 55 ms 16112 KB Output is correct
68 Correct 56 ms 16116 KB Output is correct
69 Correct 59 ms 15956 KB Output is correct
70 Correct 55 ms 16112 KB Output is correct
71 Correct 280 ms 40436 KB Output is correct
72 Correct 293 ms 40436 KB Output is correct
73 Correct 304 ms 39140 KB Output is correct
74 Correct 527 ms 39504 KB Output is correct
75 Correct 328 ms 41456 KB Output is correct
76 Correct 472 ms 39788 KB Output is correct
77 Correct 393 ms 39664 KB Output is correct
78 Correct 202 ms 43512 KB Output is correct
79 Correct 200 ms 37456 KB Output is correct
80 Correct 325 ms 40544 KB Output is correct
81 Correct 399 ms 40436 KB Output is correct
82 Correct 524 ms 39412 KB Output is correct
83 Correct 252 ms 38640 KB Output is correct
84 Correct 350 ms 39364 KB Output is correct
85 Correct 390 ms 39572 KB Output is correct
86 Correct 190 ms 37292 KB Output is correct
87 Correct 309 ms 40428 KB Output is correct
88 Correct 194 ms 37456 KB Output is correct
89 Correct 303 ms 38988 KB Output is correct
90 Correct 335 ms 39428 KB Output is correct
91 Correct 264 ms 38592 KB Output is correct
92 Correct 463 ms 39668 KB Output is correct
93 Correct 383 ms 39656 KB Output is correct
94 Correct 180 ms 37456 KB Output is correct
95 Correct 347 ms 39560 KB Output is correct
96 Correct 352 ms 39408 KB Output is correct
97 Correct 344 ms 39356 KB Output is correct
98 Correct 366 ms 39412 KB Output is correct
99 Correct 348 ms 39488 KB Output is correct
100 Correct 358 ms 39508 KB Output is correct