Submission #697660

# Submission time Handle Problem Language Result Execution time Memory
697660 2023-02-10T16:35:20 Z Jarif_Rahman Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
2000 ms 24780 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;

const int p3[16] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907};
int v[1<<20];
vector<pair<int, int>> queries[1<<7];
int dp[1594323];

void bruteforce(str &s, int &x, int &i, int k = 0, int index = 0){
    if(k == 7){
        queries[index].pb({x, i});
        return;
    }
    if(s[13+k] != '1') bruteforce(s, x, i, k+1, index);
    if(s[13+k] != '0') bruteforce(s, x, i, k+1, index+(1<<k));
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

    vector<int> ans(Q, 0);
    for(int i = 0; i < Q; i++){
        str s; cin >> s;
        if(L < 20) s = str(20-L, '0')+s;
        reverse(s.begin(), s.end());
        int x = 0;
        for(int j = 0; j < 13; j++){
            if(s[j] == '?') x+=p3[j]*2;
            else x+=(s[j]-'0')*p3[j];
        }

        bruteforce(s, x, i);
    }

    for(int k = 0; k < (1<<7); k++){
        if(queries[k].empty()) continue;
        fill(dp, dp+p3[13], 0);
        for(int i = k*(1<<13); i < (k+1)*(1<<13); i++){
            int x = 0;
            for(int j = 0; j < 13; j++) if(i&(1<<j)) x+=p3[j];
            dp[x]+=v[i];
        }

        for(int j = 0; j < 13; j++) for(int i = 0; i < p3[13]; i++){
            if((i/p3[j])%3 == 2){
                dp[i]+=dp[i-p3[j]*2]+dp[i-p3[j]];
            }
        }

        for(auto [x, i]: queries[k]) ans[i]+=dp[x];
    }

    for(int x: ans) cout << x << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 130 ms 6484 KB Output is correct
2 Correct 138 ms 6580 KB Output is correct
3 Correct 130 ms 6580 KB Output is correct
4 Correct 133 ms 6604 KB Output is correct
5 Correct 131 ms 6580 KB Output is correct
6 Correct 131 ms 6576 KB Output is correct
7 Correct 131 ms 6576 KB Output is correct
8 Correct 135 ms 6576 KB Output is correct
9 Correct 135 ms 6484 KB Output is correct
10 Correct 132 ms 6576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 6484 KB Output is correct
2 Correct 138 ms 6580 KB Output is correct
3 Correct 130 ms 6580 KB Output is correct
4 Correct 133 ms 6604 KB Output is correct
5 Correct 131 ms 6580 KB Output is correct
6 Correct 131 ms 6576 KB Output is correct
7 Correct 131 ms 6576 KB Output is correct
8 Correct 135 ms 6576 KB Output is correct
9 Correct 135 ms 6484 KB Output is correct
10 Correct 132 ms 6576 KB Output is correct
11 Correct 412 ms 22556 KB Output is correct
12 Correct 422 ms 22080 KB Output is correct
13 Correct 419 ms 21304 KB Output is correct
14 Correct 407 ms 21392 KB Output is correct
15 Correct 410 ms 22460 KB Output is correct
16 Correct 415 ms 21696 KB Output is correct
17 Correct 436 ms 21584 KB Output is correct
18 Correct 383 ms 23476 KB Output is correct
19 Correct 385 ms 20552 KB Output is correct
20 Correct 422 ms 22032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 6484 KB Output is correct
2 Correct 138 ms 6580 KB Output is correct
3 Correct 130 ms 6580 KB Output is correct
4 Correct 133 ms 6604 KB Output is correct
5 Correct 131 ms 6580 KB Output is correct
6 Correct 131 ms 6576 KB Output is correct
7 Correct 131 ms 6576 KB Output is correct
8 Correct 135 ms 6576 KB Output is correct
9 Correct 135 ms 6484 KB Output is correct
10 Correct 132 ms 6576 KB Output is correct
11 Correct 412 ms 22556 KB Output is correct
12 Correct 422 ms 22080 KB Output is correct
13 Correct 419 ms 21304 KB Output is correct
14 Correct 407 ms 21392 KB Output is correct
15 Correct 410 ms 22460 KB Output is correct
16 Correct 415 ms 21696 KB Output is correct
17 Correct 436 ms 21584 KB Output is correct
18 Correct 383 ms 23476 KB Output is correct
19 Correct 385 ms 20552 KB Output is correct
20 Correct 422 ms 22032 KB Output is correct
21 Correct 431 ms 22448 KB Output is correct
22 Correct 442 ms 22576 KB Output is correct
23 Correct 429 ms 21680 KB Output is correct
24 Correct 418 ms 21424 KB Output is correct
25 Correct 426 ms 23472 KB Output is correct
26 Correct 429 ms 22016 KB Output is correct
27 Correct 425 ms 21940 KB Output is correct
28 Correct 389 ms 24780 KB Output is correct
29 Correct 394 ms 20724 KB Output is correct
30 Correct 433 ms 22828 KB Output is correct
31 Correct 431 ms 22756 KB Output is correct
32 Correct 438 ms 22740 KB Output is correct
33 Correct 408 ms 21720 KB Output is correct
34 Correct 416 ms 21684 KB Output is correct
35 Correct 429 ms 22156 KB Output is correct
36 Correct 389 ms 20656 KB Output is correct
37 Correct 430 ms 22828 KB Output is correct
38 Correct 385 ms 20704 KB Output is correct
39 Correct 420 ms 22056 KB Output is correct
40 Correct 417 ms 21800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 6484 KB Output is correct
2 Correct 138 ms 6580 KB Output is correct
3 Correct 130 ms 6580 KB Output is correct
4 Correct 133 ms 6604 KB Output is correct
5 Correct 131 ms 6580 KB Output is correct
6 Correct 131 ms 6576 KB Output is correct
7 Correct 131 ms 6576 KB Output is correct
8 Correct 135 ms 6576 KB Output is correct
9 Correct 135 ms 6484 KB Output is correct
10 Correct 132 ms 6576 KB Output is correct
11 Execution timed out 2085 ms 18360 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 130 ms 6484 KB Output is correct
2 Correct 138 ms 6580 KB Output is correct
3 Correct 130 ms 6580 KB Output is correct
4 Correct 133 ms 6604 KB Output is correct
5 Correct 131 ms 6580 KB Output is correct
6 Correct 131 ms 6576 KB Output is correct
7 Correct 131 ms 6576 KB Output is correct
8 Correct 135 ms 6576 KB Output is correct
9 Correct 135 ms 6484 KB Output is correct
10 Correct 132 ms 6576 KB Output is correct
11 Correct 412 ms 22556 KB Output is correct
12 Correct 422 ms 22080 KB Output is correct
13 Correct 419 ms 21304 KB Output is correct
14 Correct 407 ms 21392 KB Output is correct
15 Correct 410 ms 22460 KB Output is correct
16 Correct 415 ms 21696 KB Output is correct
17 Correct 436 ms 21584 KB Output is correct
18 Correct 383 ms 23476 KB Output is correct
19 Correct 385 ms 20552 KB Output is correct
20 Correct 422 ms 22032 KB Output is correct
21 Correct 431 ms 22448 KB Output is correct
22 Correct 442 ms 22576 KB Output is correct
23 Correct 429 ms 21680 KB Output is correct
24 Correct 418 ms 21424 KB Output is correct
25 Correct 426 ms 23472 KB Output is correct
26 Correct 429 ms 22016 KB Output is correct
27 Correct 425 ms 21940 KB Output is correct
28 Correct 389 ms 24780 KB Output is correct
29 Correct 394 ms 20724 KB Output is correct
30 Correct 433 ms 22828 KB Output is correct
31 Correct 431 ms 22756 KB Output is correct
32 Correct 438 ms 22740 KB Output is correct
33 Correct 408 ms 21720 KB Output is correct
34 Correct 416 ms 21684 KB Output is correct
35 Correct 429 ms 22156 KB Output is correct
36 Correct 389 ms 20656 KB Output is correct
37 Correct 430 ms 22828 KB Output is correct
38 Correct 385 ms 20704 KB Output is correct
39 Correct 420 ms 22056 KB Output is correct
40 Correct 417 ms 21800 KB Output is correct
41 Execution timed out 2085 ms 18360 KB Time limit exceeded
42 Halted 0 ms 0 KB -