답안 #926985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926985 2024-02-14T06:16:56 Z manizare Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
653 ms 49832 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long 
#define pii pair <int,int>
#define PII pair<pii , pii>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
const int maxn = 2e6 + 10  , c = 6 , maxp = 15e5 + 10 , inf=  1e18+10 ;
int d1[maxn] , d2[maxn] ;
signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n  ,q ;
    cin >> n >> q; 
    string s;
    cin >> s ;
    rep(i , 0 , (1<<n)-1){
        d1[i] = (s[i]-'0'); 
        d2[i] = (s[i]-'0');
    }
    rep(i , 0 , n-1){
        rep(j , 0 , (1<<n)-1){
            if(j>>i&1){
                d2[j]+=d2[j^(1<<i)] ;
            }else{
                d1[j]+=d1[j^(1<<i)] ;
            }
        }
    }
    while(q--){
        string t;
        cin >> t ;
        reverse(all(t)) ;
        int a=0,b=0,c=0;
        rep(i , 0 ,n-1){
            if(t[i]=='?')a+=(1<<i);
            if(t[i]=='0')b+=(1<<i);
            if(t[i]=='1')c+=(1<<i);
        }
        if(__builtin_popcount(a) <=6){
            int ans =0;
            for(int ms = a ; ; ms = (ms-1)&a){
                ans += s[ms|c]-'0' ;
                if(ms == 0)break ;
            }
            cout << ans << "\n";
            continue;
        }
        if(__builtin_popcount(b) <= 6){
            int ans =0 ;
            for(int ms = b ; ; ms = (ms-1)&b){
                if(__builtin_popcount(ms)%2){
                    ans -= d1[ms|c]; 
                }else{
                    ans += d1[ms|c] ;
                }
                if(ms==0)break ;
            }
            cout << ans << "\n";
            continue ;
        }
        int ans = 0 ;
        for(int ms = c ;  ;ms = (ms-1)&c){
            if((__builtin_popcount(c)-__builtin_popcount(ms))%2){
                ans -= d2[ms|a] ;
            }else{
                ans += d2[ms|a] ;
            }
            if(ms==0)break ;
        }
        cout << ans << "\n" ;
    }
    return 0;
}
/*
 
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 200 ms 17156 KB Output is correct
12 Correct 202 ms 16856 KB Output is correct
13 Correct 190 ms 15980 KB Output is correct
14 Correct 185 ms 16164 KB Output is correct
15 Correct 256 ms 17228 KB Output is correct
16 Correct 214 ms 16468 KB Output is correct
17 Correct 214 ms 16360 KB Output is correct
18 Correct 167 ms 18260 KB Output is correct
19 Correct 167 ms 15184 KB Output is correct
20 Correct 213 ms 16844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 200 ms 17156 KB Output is correct
12 Correct 202 ms 16856 KB Output is correct
13 Correct 190 ms 15980 KB Output is correct
14 Correct 185 ms 16164 KB Output is correct
15 Correct 256 ms 17228 KB Output is correct
16 Correct 214 ms 16468 KB Output is correct
17 Correct 214 ms 16360 KB Output is correct
18 Correct 167 ms 18260 KB Output is correct
19 Correct 167 ms 15184 KB Output is correct
20 Correct 213 ms 16844 KB Output is correct
21 Correct 194 ms 20160 KB Output is correct
22 Correct 276 ms 20304 KB Output is correct
23 Correct 231 ms 19284 KB Output is correct
24 Correct 242 ms 19300 KB Output is correct
25 Correct 237 ms 21236 KB Output is correct
26 Correct 255 ms 19616 KB Output is correct
27 Correct 256 ms 19596 KB Output is correct
28 Correct 149 ms 22288 KB Output is correct
29 Correct 186 ms 18260 KB Output is correct
30 Correct 225 ms 20276 KB Output is correct
31 Correct 299 ms 20564 KB Output is correct
32 Correct 250 ms 20308 KB Output is correct
33 Correct 207 ms 19280 KB Output is correct
34 Correct 253 ms 19280 KB Output is correct
35 Correct 253 ms 19712 KB Output is correct
36 Correct 142 ms 18136 KB Output is correct
37 Correct 247 ms 20120 KB Output is correct
38 Correct 196 ms 18220 KB Output is correct
39 Correct 230 ms 19280 KB Output is correct
40 Correct 226 ms 19104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 39 ms 22544 KB Output is correct
12 Correct 37 ms 22548 KB Output is correct
13 Correct 40 ms 22256 KB Output is correct
14 Correct 48 ms 22256 KB Output is correct
15 Correct 39 ms 22512 KB Output is correct
16 Correct 45 ms 22292 KB Output is correct
17 Correct 55 ms 22324 KB Output is correct
18 Correct 29 ms 22516 KB Output is correct
19 Correct 36 ms 22260 KB Output is correct
20 Correct 49 ms 22516 KB Output is correct
21 Correct 41 ms 22520 KB Output is correct
22 Correct 50 ms 22456 KB Output is correct
23 Correct 45 ms 22276 KB Output is correct
24 Correct 39 ms 22264 KB Output is correct
25 Correct 54 ms 22256 KB Output is correct
26 Correct 30 ms 22264 KB Output is correct
27 Correct 34 ms 22520 KB Output is correct
28 Correct 35 ms 22256 KB Output is correct
29 Correct 41 ms 22264 KB Output is correct
30 Correct 54 ms 22260 KB Output is correct
31 Correct 34 ms 22264 KB Output is correct
32 Correct 50 ms 22512 KB Output is correct
33 Correct 63 ms 22512 KB Output is correct
34 Correct 28 ms 22260 KB Output is correct
35 Correct 41 ms 22288 KB Output is correct
36 Correct 43 ms 22396 KB Output is correct
37 Correct 48 ms 22296 KB Output is correct
38 Correct 41 ms 22300 KB Output is correct
39 Correct 48 ms 22280 KB Output is correct
40 Correct 43 ms 22324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 200 ms 17156 KB Output is correct
12 Correct 202 ms 16856 KB Output is correct
13 Correct 190 ms 15980 KB Output is correct
14 Correct 185 ms 16164 KB Output is correct
15 Correct 256 ms 17228 KB Output is correct
16 Correct 214 ms 16468 KB Output is correct
17 Correct 214 ms 16360 KB Output is correct
18 Correct 167 ms 18260 KB Output is correct
19 Correct 167 ms 15184 KB Output is correct
20 Correct 213 ms 16844 KB Output is correct
21 Correct 194 ms 20160 KB Output is correct
22 Correct 276 ms 20304 KB Output is correct
23 Correct 231 ms 19284 KB Output is correct
24 Correct 242 ms 19300 KB Output is correct
25 Correct 237 ms 21236 KB Output is correct
26 Correct 255 ms 19616 KB Output is correct
27 Correct 256 ms 19596 KB Output is correct
28 Correct 149 ms 22288 KB Output is correct
29 Correct 186 ms 18260 KB Output is correct
30 Correct 225 ms 20276 KB Output is correct
31 Correct 299 ms 20564 KB Output is correct
32 Correct 250 ms 20308 KB Output is correct
33 Correct 207 ms 19280 KB Output is correct
34 Correct 253 ms 19280 KB Output is correct
35 Correct 253 ms 19712 KB Output is correct
36 Correct 142 ms 18136 KB Output is correct
37 Correct 247 ms 20120 KB Output is correct
38 Correct 196 ms 18220 KB Output is correct
39 Correct 230 ms 19280 KB Output is correct
40 Correct 226 ms 19104 KB Output is correct
41 Correct 39 ms 22544 KB Output is correct
42 Correct 37 ms 22548 KB Output is correct
43 Correct 40 ms 22256 KB Output is correct
44 Correct 48 ms 22256 KB Output is correct
45 Correct 39 ms 22512 KB Output is correct
46 Correct 45 ms 22292 KB Output is correct
47 Correct 55 ms 22324 KB Output is correct
48 Correct 29 ms 22516 KB Output is correct
49 Correct 36 ms 22260 KB Output is correct
50 Correct 49 ms 22516 KB Output is correct
51 Correct 41 ms 22520 KB Output is correct
52 Correct 50 ms 22456 KB Output is correct
53 Correct 45 ms 22276 KB Output is correct
54 Correct 39 ms 22264 KB Output is correct
55 Correct 54 ms 22256 KB Output is correct
56 Correct 30 ms 22264 KB Output is correct
57 Correct 34 ms 22520 KB Output is correct
58 Correct 35 ms 22256 KB Output is correct
59 Correct 41 ms 22264 KB Output is correct
60 Correct 54 ms 22260 KB Output is correct
61 Correct 34 ms 22264 KB Output is correct
62 Correct 50 ms 22512 KB Output is correct
63 Correct 63 ms 22512 KB Output is correct
64 Correct 28 ms 22260 KB Output is correct
65 Correct 41 ms 22288 KB Output is correct
66 Correct 43 ms 22396 KB Output is correct
67 Correct 48 ms 22296 KB Output is correct
68 Correct 41 ms 22300 KB Output is correct
69 Correct 48 ms 22280 KB Output is correct
70 Correct 43 ms 22324 KB Output is correct
71 Correct 311 ms 46772 KB Output is correct
72 Correct 371 ms 46940 KB Output is correct
73 Correct 355 ms 45448 KB Output is correct
74 Correct 573 ms 45808 KB Output is correct
75 Correct 430 ms 47644 KB Output is correct
76 Correct 516 ms 46148 KB Output is correct
77 Correct 646 ms 45896 KB Output is correct
78 Correct 208 ms 49832 KB Output is correct
79 Correct 300 ms 43764 KB Output is correct
80 Correct 335 ms 46780 KB Output is correct
81 Correct 470 ms 46852 KB Output is correct
82 Correct 563 ms 45780 KB Output is correct
83 Correct 299 ms 44828 KB Output is correct
84 Correct 418 ms 45848 KB Output is correct
85 Correct 522 ms 45928 KB Output is correct
86 Correct 210 ms 43636 KB Output is correct
87 Correct 292 ms 46696 KB Output is correct
88 Correct 394 ms 43808 KB Output is correct
89 Correct 369 ms 45404 KB Output is correct
90 Correct 413 ms 45808 KB Output is correct
91 Correct 309 ms 44788 KB Output is correct
92 Correct 653 ms 45988 KB Output is correct
93 Correct 538 ms 46004 KB Output is correct
94 Correct 197 ms 43636 KB Output is correct
95 Correct 553 ms 45804 KB Output is correct
96 Correct 479 ms 45808 KB Output is correct
97 Correct 494 ms 45916 KB Output is correct
98 Correct 506 ms 45756 KB Output is correct
99 Correct 448 ms 45808 KB Output is correct
100 Correct 522 ms 45812 KB Output is correct