Submission #810215

# Submission time Handle Problem Language Result Execution time Memory
810215 2023-08-06T06:37:30 Z QwertyPi Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
2000 ms 25988 KB
#include <bits/stdc++.h>
using namespace std;

int ans[1 << 20];
int f(char c){
    if(c == '0') return 0;
    if(c == '1') return 1;
    if(c == '?') return 2;
    return -1;
}

vector<pair<long long, int>> Q;
void solve(int L, int* a, int l, int r){
    if(L == 0){
        for(int i = l; i < r; i++){
            ans[Q[i].second] = a[0];
        }
        return;
    }
    int mid_0 = l; while(mid_0 < r && (Q[mid_0].first & (3LL << (L - 1) * 2)) == 0) mid_0++;
    int mid_1 = mid_0; while(mid_1 < r && ((Q[mid_1].first & (3LL << (L - 1) * 2)) >> (L - 1) * 2) == 1) mid_1++;
    // 0
    solve(L - 1, a, l, mid_0);
    // 1
    solve(L - 1, a + (1 << L - 1), mid_0, mid_1);
    // ?
    for(int i = 0; i < (1 << L - 1); i++) a[i] += a[i + (1 << L - 1)];
    solve(L - 1, a, mid_1, r);
    for(int i = 0; i < (1 << L - 1); i++) a[i] -= a[i + (1 << L - 1)];
}

int a[1 << 20];
int32_t main(){
    cin.tie(0); cout.tie(0)->sync_with_stdio(false);
    int L, q; cin >> L >> q; string s; cin >> s;
    for(int i = 0; i < (1 << L); i++) a[i] = s[i] - '0';
    for(int i = 0; i < q; i++){
        string s; cin >> s; reverse(s.begin(), s.end());
        long long b = 0;
        for(int j = 0; j < L; j++){
            b |= f(s[j]) * (1LL << j * 2);
        }
        Q.push_back({b, i});
    }
    sort(Q.begin(), Q.end());
    solve(L, a, 0, Q.size());

    for(int i = 0; i < q; i++){
        cout << ans[i] << '\n';
    }
}

Compilation message

snake_escaping.cpp: In function 'void solve(int, int*, int, int)':
snake_escaping.cpp:25:30: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   25 |     solve(L - 1, a + (1 << L - 1), mid_0, mid_1);
      |                            ~~^~~
snake_escaping.cpp:27:32: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   27 |     for(int i = 0; i < (1 << L - 1); i++) a[i] += a[i + (1 << L - 1)];
      |                              ~~^~~
snake_escaping.cpp:27:65: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   27 |     for(int i = 0; i < (1 << L - 1); i++) a[i] += a[i + (1 << L - 1)];
      |                                                               ~~^~~
snake_escaping.cpp:29:32: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   29 |     for(int i = 0; i < (1 << L - 1); i++) a[i] -= a[i + (1 << L - 1)];
      |                              ~~^~~
snake_escaping.cpp:29:65: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   29 |     for(int i = 0; i < (1 << L - 1); i++) a[i] -= a[i + (1 << L - 1)];
      |                                                               ~~^~~
# Verdict Execution time Memory 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 340 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
# Verdict Execution time Memory 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 340 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 264 ms 23964 KB Output is correct
12 Correct 269 ms 23632 KB Output is correct
13 Correct 286 ms 22920 KB Output is correct
14 Correct 275 ms 23032 KB Output is correct
15 Correct 268 ms 23932 KB Output is correct
16 Correct 283 ms 23144 KB Output is correct
17 Correct 288 ms 23168 KB Output is correct
18 Correct 155 ms 24972 KB Output is correct
19 Correct 260 ms 22012 KB Output is correct
20 Correct 267 ms 23652 KB Output is correct
# Verdict Execution time Memory 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 340 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 264 ms 23964 KB Output is correct
12 Correct 269 ms 23632 KB Output is correct
13 Correct 286 ms 22920 KB Output is correct
14 Correct 275 ms 23032 KB Output is correct
15 Correct 268 ms 23932 KB Output is correct
16 Correct 283 ms 23144 KB Output is correct
17 Correct 288 ms 23168 KB Output is correct
18 Correct 155 ms 24972 KB Output is correct
19 Correct 260 ms 22012 KB Output is correct
20 Correct 267 ms 23652 KB Output is correct
21 Correct 283 ms 23976 KB Output is correct
22 Correct 297 ms 24252 KB Output is correct
23 Correct 320 ms 23168 KB Output is correct
24 Correct 308 ms 23300 KB Output is correct
25 Correct 336 ms 25144 KB Output is correct
26 Correct 318 ms 23772 KB Output is correct
27 Correct 326 ms 23708 KB Output is correct
28 Correct 165 ms 25988 KB Output is correct
29 Correct 280 ms 22072 KB Output is correct
30 Correct 295 ms 24144 KB Output is correct
31 Correct 300 ms 24044 KB Output is correct
32 Correct 312 ms 24084 KB Output is correct
33 Correct 290 ms 23128 KB Output is correct
34 Correct 313 ms 23356 KB Output is correct
35 Correct 327 ms 23720 KB Output is correct
36 Correct 168 ms 22296 KB Output is correct
37 Correct 295 ms 24228 KB Output is correct
38 Correct 291 ms 22308 KB Output is correct
39 Correct 308 ms 23508 KB Output is correct
40 Correct 308 ms 23304 KB Output is correct
# Verdict Execution time Memory 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 340 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 Execution timed out 2054 ms 7540 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 340 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 264 ms 23964 KB Output is correct
12 Correct 269 ms 23632 KB Output is correct
13 Correct 286 ms 22920 KB Output is correct
14 Correct 275 ms 23032 KB Output is correct
15 Correct 268 ms 23932 KB Output is correct
16 Correct 283 ms 23144 KB Output is correct
17 Correct 288 ms 23168 KB Output is correct
18 Correct 155 ms 24972 KB Output is correct
19 Correct 260 ms 22012 KB Output is correct
20 Correct 267 ms 23652 KB Output is correct
21 Correct 283 ms 23976 KB Output is correct
22 Correct 297 ms 24252 KB Output is correct
23 Correct 320 ms 23168 KB Output is correct
24 Correct 308 ms 23300 KB Output is correct
25 Correct 336 ms 25144 KB Output is correct
26 Correct 318 ms 23772 KB Output is correct
27 Correct 326 ms 23708 KB Output is correct
28 Correct 165 ms 25988 KB Output is correct
29 Correct 280 ms 22072 KB Output is correct
30 Correct 295 ms 24144 KB Output is correct
31 Correct 300 ms 24044 KB Output is correct
32 Correct 312 ms 24084 KB Output is correct
33 Correct 290 ms 23128 KB Output is correct
34 Correct 313 ms 23356 KB Output is correct
35 Correct 327 ms 23720 KB Output is correct
36 Correct 168 ms 22296 KB Output is correct
37 Correct 295 ms 24228 KB Output is correct
38 Correct 291 ms 22308 KB Output is correct
39 Correct 308 ms 23508 KB Output is correct
40 Correct 308 ms 23304 KB Output is correct
41 Execution timed out 2054 ms 7540 KB Time limit exceeded
42 Halted 0 ms 0 KB -