답안 #792475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792475 2023-07-25T05:20:07 Z Cookie Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1049 ms 43388 KB
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ll mxn = 3e5 + 5, base = 972663749;
const ll mod = 911382323, mxv = 1e9 + 1, inf = 2e9;
int l, q;
int big[(1 << 21)], small[(1 << 21)], cnt[(1 << 20)];
string s;
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    cin >> l >> q;
    cin >> s;
    for(int i = 0; i < (1 << l); i++){
        cnt[i] = __builtin_popcount(i);
        big[i] = (s[i] - '0'); small[i] = (s[i] - '0');
    }
    for(int i = 0; i < l; i++){
        for(int j = 0; j < (1 << l); j++){
            if(j & (1 << i))small[j] += small[j ^ (1 << i)];
            else big[j] += big[j ^ (1 << i)];
        }
    }
    
    
    while(q--){
       
       char c;
        int zero = 0, one = 0, que = 0;
        for(int i = 0; i < l; i++){
            cin >> c;
            if(c == '0')zero += (1 << (l - i - 1));
            else if(c == '1')one += (1 << (l - i - 1));
            else que += (1 << (l - i - 1));
        }
        int ans = 0;
        if(__builtin_popcount(que) <= 6){
            int mask = one;
            for(int j = que;j; j = (j - 1) & que){
                //cout << (mask | j) << " ";
                ans += (s[mask | j] - '0');
                
            }
            ans += (s[mask] - '0');
        }else if(__builtin_popcount(one) <= 6){
            int mask = que;
            for(int j = one;j; j = (j - 1) & one){
                if((cnt[one] - cnt[j]) & 1)ans -= small[mask | j];
                else ans += small[mask | j];
               
            }
            if(cnt[one] & 1)ans -= small[mask];
            else ans += small[mask];
        }else{
            int mask = one;
            for(int j = zero;j; j = (j - 1) & zero){
                if(cnt[j] & 1)ans -= big[mask | j];
                else ans += big[mask | j];
            }
            ans += big[mask];
        }
        cout << ans << "\n";
    }
    return(0);
}
# 결과 실행 시간 메모리 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 332 KB Output is correct
6 Correct 1 ms 336 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 336 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 332 KB Output is correct
6 Correct 1 ms 336 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 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 244 ms 8292 KB Output is correct
12 Correct 300 ms 7896 KB Output is correct
13 Correct 262 ms 7232 KB Output is correct
14 Correct 287 ms 7216 KB Output is correct
15 Correct 278 ms 8288 KB Output is correct
16 Correct 273 ms 7492 KB Output is correct
17 Correct 293 ms 7444 KB Output is correct
18 Correct 164 ms 9220 KB Output is correct
19 Correct 262 ms 6260 KB Output is correct
20 Correct 292 ms 7988 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 332 KB Output is correct
6 Correct 1 ms 336 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 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 244 ms 8292 KB Output is correct
12 Correct 300 ms 7896 KB Output is correct
13 Correct 262 ms 7232 KB Output is correct
14 Correct 287 ms 7216 KB Output is correct
15 Correct 278 ms 8288 KB Output is correct
16 Correct 273 ms 7492 KB Output is correct
17 Correct 293 ms 7444 KB Output is correct
18 Correct 164 ms 9220 KB Output is correct
19 Correct 262 ms 6260 KB Output is correct
20 Correct 292 ms 7988 KB Output is correct
21 Correct 389 ms 8056 KB Output is correct
22 Correct 343 ms 8104 KB Output is correct
23 Correct 334 ms 7340 KB Output is correct
24 Correct 336 ms 7164 KB Output is correct
25 Correct 305 ms 9200 KB Output is correct
26 Correct 327 ms 7616 KB Output is correct
27 Correct 370 ms 7516 KB Output is correct
28 Correct 201 ms 10212 KB Output is correct
29 Correct 279 ms 6000 KB Output is correct
30 Correct 383 ms 8208 KB Output is correct
31 Correct 347 ms 8060 KB Output is correct
32 Correct 330 ms 7952 KB Output is correct
33 Correct 266 ms 6860 KB Output is correct
34 Correct 339 ms 6996 KB Output is correct
35 Correct 412 ms 7468 KB Output is correct
36 Correct 210 ms 6020 KB Output is correct
37 Correct 314 ms 8472 KB Output is correct
38 Correct 277 ms 6564 KB Output is correct
39 Correct 347 ms 7740 KB Output is correct
40 Correct 321 ms 7536 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 332 KB Output is correct
6 Correct 1 ms 336 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 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 44 ms 15980 KB Output is correct
12 Correct 39 ms 16048 KB Output is correct
13 Correct 44 ms 16004 KB Output is correct
14 Correct 49 ms 16108 KB Output is correct
15 Correct 57 ms 16112 KB Output is correct
16 Correct 51 ms 15968 KB Output is correct
17 Correct 47 ms 15952 KB Output is correct
18 Correct 32 ms 16240 KB Output is correct
19 Correct 43 ms 15908 KB Output is correct
20 Correct 46 ms 16004 KB Output is correct
21 Correct 55 ms 16048 KB Output is correct
22 Correct 50 ms 15972 KB Output is correct
23 Correct 39 ms 15964 KB Output is correct
24 Correct 44 ms 16048 KB Output is correct
25 Correct 70 ms 15956 KB Output is correct
26 Correct 35 ms 15916 KB Output is correct
27 Correct 40 ms 16088 KB Output is correct
28 Correct 46 ms 15960 KB Output is correct
29 Correct 41 ms 15912 KB Output is correct
30 Correct 49 ms 16012 KB Output is correct
31 Correct 43 ms 15968 KB Output is correct
32 Correct 55 ms 16020 KB Output is correct
33 Correct 50 ms 15936 KB Output is correct
34 Correct 48 ms 15852 KB Output is correct
35 Correct 72 ms 15956 KB Output is correct
36 Correct 44 ms 15976 KB Output is correct
37 Correct 51 ms 16056 KB Output is correct
38 Correct 46 ms 15968 KB Output is correct
39 Correct 46 ms 15972 KB Output is correct
40 Correct 56 ms 16040 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 332 KB Output is correct
6 Correct 1 ms 336 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 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 244 ms 8292 KB Output is correct
12 Correct 300 ms 7896 KB Output is correct
13 Correct 262 ms 7232 KB Output is correct
14 Correct 287 ms 7216 KB Output is correct
15 Correct 278 ms 8288 KB Output is correct
16 Correct 273 ms 7492 KB Output is correct
17 Correct 293 ms 7444 KB Output is correct
18 Correct 164 ms 9220 KB Output is correct
19 Correct 262 ms 6260 KB Output is correct
20 Correct 292 ms 7988 KB Output is correct
21 Correct 389 ms 8056 KB Output is correct
22 Correct 343 ms 8104 KB Output is correct
23 Correct 334 ms 7340 KB Output is correct
24 Correct 336 ms 7164 KB Output is correct
25 Correct 305 ms 9200 KB Output is correct
26 Correct 327 ms 7616 KB Output is correct
27 Correct 370 ms 7516 KB Output is correct
28 Correct 201 ms 10212 KB Output is correct
29 Correct 279 ms 6000 KB Output is correct
30 Correct 383 ms 8208 KB Output is correct
31 Correct 347 ms 8060 KB Output is correct
32 Correct 330 ms 7952 KB Output is correct
33 Correct 266 ms 6860 KB Output is correct
34 Correct 339 ms 6996 KB Output is correct
35 Correct 412 ms 7468 KB Output is correct
36 Correct 210 ms 6020 KB Output is correct
37 Correct 314 ms 8472 KB Output is correct
38 Correct 277 ms 6564 KB Output is correct
39 Correct 347 ms 7740 KB Output is correct
40 Correct 321 ms 7536 KB Output is correct
41 Correct 44 ms 15980 KB Output is correct
42 Correct 39 ms 16048 KB Output is correct
43 Correct 44 ms 16004 KB Output is correct
44 Correct 49 ms 16108 KB Output is correct
45 Correct 57 ms 16112 KB Output is correct
46 Correct 51 ms 15968 KB Output is correct
47 Correct 47 ms 15952 KB Output is correct
48 Correct 32 ms 16240 KB Output is correct
49 Correct 43 ms 15908 KB Output is correct
50 Correct 46 ms 16004 KB Output is correct
51 Correct 55 ms 16048 KB Output is correct
52 Correct 50 ms 15972 KB Output is correct
53 Correct 39 ms 15964 KB Output is correct
54 Correct 44 ms 16048 KB Output is correct
55 Correct 70 ms 15956 KB Output is correct
56 Correct 35 ms 15916 KB Output is correct
57 Correct 40 ms 16088 KB Output is correct
58 Correct 46 ms 15960 KB Output is correct
59 Correct 41 ms 15912 KB Output is correct
60 Correct 49 ms 16012 KB Output is correct
61 Correct 43 ms 15968 KB Output is correct
62 Correct 55 ms 16020 KB Output is correct
63 Correct 50 ms 15936 KB Output is correct
64 Correct 48 ms 15852 KB Output is correct
65 Correct 72 ms 15956 KB Output is correct
66 Correct 44 ms 15976 KB Output is correct
67 Correct 51 ms 16056 KB Output is correct
68 Correct 46 ms 15968 KB Output is correct
69 Correct 46 ms 15972 KB Output is correct
70 Correct 56 ms 16040 KB Output is correct
71 Correct 531 ms 40384 KB Output is correct
72 Correct 484 ms 40492 KB Output is correct
73 Correct 534 ms 38936 KB Output is correct
74 Correct 658 ms 39340 KB Output is correct
75 Correct 599 ms 41068 KB Output is correct
76 Correct 790 ms 39576 KB Output is correct
77 Correct 618 ms 39532 KB Output is correct
78 Correct 271 ms 43388 KB Output is correct
79 Correct 491 ms 36988 KB Output is correct
80 Correct 639 ms 40152 KB Output is correct
81 Correct 1049 ms 40016 KB Output is correct
82 Correct 697 ms 39368 KB Output is correct
83 Correct 431 ms 38448 KB Output is correct
84 Correct 648 ms 39360 KB Output is correct
85 Correct 766 ms 39556 KB Output is correct
86 Correct 275 ms 37248 KB Output is correct
87 Correct 420 ms 40300 KB Output is correct
88 Correct 476 ms 37232 KB Output is correct
89 Correct 478 ms 38956 KB Output is correct
90 Correct 526 ms 39272 KB Output is correct
91 Correct 428 ms 38452 KB Output is correct
92 Correct 683 ms 39504 KB Output is correct
93 Correct 907 ms 39500 KB Output is correct
94 Correct 405 ms 37296 KB Output is correct
95 Correct 764 ms 39444 KB Output is correct
96 Correct 631 ms 39412 KB Output is correct
97 Correct 566 ms 39392 KB Output is correct
98 Correct 790 ms 39364 KB Output is correct
99 Correct 621 ms 39400 KB Output is correct
100 Correct 558 ms 39452 KB Output is correct