Submission #873286

# Submission time Handle Problem Language Result Execution time Memory
873286 2023-11-14T18:46:01 Z garam1732 Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
755 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define bl " "
#define endl "\n"
#define all(v) v.begin(), v.end()
#define comp(v) v.erase(unique(all(v)), v.end())
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1000100;
const int MOD = 1e9+7;

struct Query {
    string s; int x;
}qry[MAXN];

vector<int> v;
int ans[MAXN], l;

void solve(int s, int e, vector<int>& v, int p, int x) {
    if(s > e) return;
    if(x == 0) {
        for(int i = s; i <= e; i++) ans[qry[i].x] = v[p];
        return;
    }

    int a = s;
    for(a = s; a <= e; a++) {
        if(qry[a].s[l-x] != '0') break;
    }

    solve(s, a-1, v, p, x-1);

    s = a;
    for(; a <= e; a++) {
        if(qry[a].s[l-x] != '1') break;
    }

    solve(s, a-1, v, p+(1<<(x-1)), x-1);

    s = a;
    vector<int> w;
    for(int i = p; i < p+(1<<(x-1)); i++) w.push_back(v[i]+v[i+(1<<(x-1))]);
    solve(s, e, w, 0, x-1);
}

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

    int q; cin >> l >> q;
    string s; cin >> s;
    for(int i = 0; i < s.size(); i++) v.push_back(s[i]-'0');

    for(int i = 0; i < q; i++) {
        cin >> qry[i].s; qry[i].x = i;
    }

    sort(qry, qry+q, [](Query a, Query b){return a.s < b.s;});
    solve(0, q-1, v, 0, l);

    for(int i = 0; i < q; i++) cout << ans[i] << endl;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int i = 0; i < s.size(); i++) v.push_back(s[i]-'0');
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 41560 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 10 ms 41308 KB Output is correct
5 Correct 8 ms 41308 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 9 ms 41308 KB Output is correct
9 Correct 10 ms 41308 KB Output is correct
10 Correct 8 ms 41304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 41560 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 10 ms 41308 KB Output is correct
5 Correct 8 ms 41308 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 9 ms 41308 KB Output is correct
9 Correct 10 ms 41308 KB Output is correct
10 Correct 8 ms 41304 KB Output is correct
11 Correct 602 ms 47420 KB Output is correct
12 Correct 578 ms 47164 KB Output is correct
13 Correct 602 ms 46416 KB Output is correct
14 Correct 574 ms 46404 KB Output is correct
15 Correct 576 ms 47412 KB Output is correct
16 Correct 620 ms 46672 KB Output is correct
17 Correct 646 ms 46912 KB Output is correct
18 Correct 498 ms 48520 KB Output is correct
19 Correct 559 ms 45300 KB Output is correct
20 Correct 585 ms 47168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 41560 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 10 ms 41308 KB Output is correct
5 Correct 8 ms 41308 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 9 ms 41308 KB Output is correct
9 Correct 10 ms 41308 KB Output is correct
10 Correct 8 ms 41304 KB Output is correct
11 Correct 602 ms 47420 KB Output is correct
12 Correct 578 ms 47164 KB Output is correct
13 Correct 602 ms 46416 KB Output is correct
14 Correct 574 ms 46404 KB Output is correct
15 Correct 576 ms 47412 KB Output is correct
16 Correct 620 ms 46672 KB Output is correct
17 Correct 646 ms 46912 KB Output is correct
18 Correct 498 ms 48520 KB Output is correct
19 Correct 559 ms 45300 KB Output is correct
20 Correct 585 ms 47168 KB Output is correct
21 Correct 593 ms 47500 KB Output is correct
22 Correct 617 ms 47876 KB Output is correct
23 Correct 695 ms 46724 KB Output is correct
24 Correct 674 ms 46472 KB Output is correct
25 Correct 674 ms 48468 KB Output is correct
26 Correct 695 ms 47256 KB Output is correct
27 Correct 732 ms 46896 KB Output is correct
28 Correct 499 ms 49544 KB Output is correct
29 Correct 628 ms 45452 KB Output is correct
30 Correct 614 ms 47496 KB Output is correct
31 Correct 714 ms 47696 KB Output is correct
32 Correct 682 ms 47500 KB Output is correct
33 Correct 642 ms 46468 KB Output is correct
34 Correct 708 ms 46472 KB Output is correct
35 Correct 755 ms 46936 KB Output is correct
36 Correct 525 ms 45652 KB Output is correct
37 Correct 586 ms 47496 KB Output is correct
38 Correct 619 ms 45448 KB Output is correct
39 Correct 691 ms 46672 KB Output is correct
40 Correct 678 ms 46472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 41560 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 10 ms 41308 KB Output is correct
5 Correct 8 ms 41308 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 9 ms 41308 KB Output is correct
9 Correct 10 ms 41308 KB Output is correct
10 Correct 8 ms 41304 KB Output is correct
11 Correct 103 ms 55096 KB Output is correct
12 Correct 115 ms 54924 KB Output is correct
13 Correct 269 ms 55092 KB Output is correct
14 Correct 327 ms 54936 KB Output is correct
15 Correct 210 ms 55132 KB Output is correct
16 Correct 330 ms 55268 KB Output is correct
17 Correct 307 ms 55016 KB Output is correct
18 Correct 57 ms 55268 KB Output is correct
19 Correct 112 ms 55340 KB Output is correct
20 Correct 124 ms 54936 KB Output is correct
21 Correct 245 ms 54848 KB Output is correct
22 Correct 316 ms 55100 KB Output is correct
23 Correct 240 ms 54892 KB Output is correct
24 Correct 332 ms 55344 KB Output is correct
25 Correct 270 ms 54936 KB Output is correct
26 Correct 60 ms 55012 KB Output is correct
27 Correct 113 ms 54924 KB Output is correct
28 Correct 111 ms 55064 KB Output is correct
29 Correct 266 ms 55016 KB Output is correct
30 Correct 279 ms 55176 KB Output is correct
31 Correct 216 ms 54936 KB Output is correct
32 Correct 302 ms 54928 KB Output is correct
33 Correct 354 ms 55096 KB Output is correct
34 Correct 59 ms 55016 KB Output is correct
35 Correct 303 ms 54960 KB Output is correct
36 Correct 265 ms 55028 KB Output is correct
37 Correct 291 ms 55100 KB Output is correct
38 Correct 292 ms 55092 KB Output is correct
39 Correct 272 ms 54928 KB Output is correct
40 Correct 253 ms 55012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 41560 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 10 ms 41308 KB Output is correct
5 Correct 8 ms 41308 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 9 ms 41308 KB Output is correct
9 Correct 10 ms 41308 KB Output is correct
10 Correct 8 ms 41304 KB Output is correct
11 Correct 602 ms 47420 KB Output is correct
12 Correct 578 ms 47164 KB Output is correct
13 Correct 602 ms 46416 KB Output is correct
14 Correct 574 ms 46404 KB Output is correct
15 Correct 576 ms 47412 KB Output is correct
16 Correct 620 ms 46672 KB Output is correct
17 Correct 646 ms 46912 KB Output is correct
18 Correct 498 ms 48520 KB Output is correct
19 Correct 559 ms 45300 KB Output is correct
20 Correct 585 ms 47168 KB Output is correct
21 Correct 593 ms 47500 KB Output is correct
22 Correct 617 ms 47876 KB Output is correct
23 Correct 695 ms 46724 KB Output is correct
24 Correct 674 ms 46472 KB Output is correct
25 Correct 674 ms 48468 KB Output is correct
26 Correct 695 ms 47256 KB Output is correct
27 Correct 732 ms 46896 KB Output is correct
28 Correct 499 ms 49544 KB Output is correct
29 Correct 628 ms 45452 KB Output is correct
30 Correct 614 ms 47496 KB Output is correct
31 Correct 714 ms 47696 KB Output is correct
32 Correct 682 ms 47500 KB Output is correct
33 Correct 642 ms 46468 KB Output is correct
34 Correct 708 ms 46472 KB Output is correct
35 Correct 755 ms 46936 KB Output is correct
36 Correct 525 ms 45652 KB Output is correct
37 Correct 586 ms 47496 KB Output is correct
38 Correct 619 ms 45448 KB Output is correct
39 Correct 691 ms 46672 KB Output is correct
40 Correct 678 ms 46472 KB Output is correct
41 Correct 103 ms 55096 KB Output is correct
42 Correct 115 ms 54924 KB Output is correct
43 Correct 269 ms 55092 KB Output is correct
44 Correct 327 ms 54936 KB Output is correct
45 Correct 210 ms 55132 KB Output is correct
46 Correct 330 ms 55268 KB Output is correct
47 Correct 307 ms 55016 KB Output is correct
48 Correct 57 ms 55268 KB Output is correct
49 Correct 112 ms 55340 KB Output is correct
50 Correct 124 ms 54936 KB Output is correct
51 Correct 245 ms 54848 KB Output is correct
52 Correct 316 ms 55100 KB Output is correct
53 Correct 240 ms 54892 KB Output is correct
54 Correct 332 ms 55344 KB Output is correct
55 Correct 270 ms 54936 KB Output is correct
56 Correct 60 ms 55012 KB Output is correct
57 Correct 113 ms 54924 KB Output is correct
58 Correct 111 ms 55064 KB Output is correct
59 Correct 266 ms 55016 KB Output is correct
60 Correct 279 ms 55176 KB Output is correct
61 Correct 216 ms 54936 KB Output is correct
62 Correct 302 ms 54928 KB Output is correct
63 Correct 354 ms 55096 KB Output is correct
64 Correct 59 ms 55016 KB Output is correct
65 Correct 303 ms 54960 KB Output is correct
66 Correct 265 ms 55028 KB Output is correct
67 Correct 291 ms 55100 KB Output is correct
68 Correct 292 ms 55092 KB Output is correct
69 Correct 272 ms 54928 KB Output is correct
70 Correct 253 ms 55012 KB Output is correct
71 Runtime error 64 ms 65536 KB Execution killed with signal 9
72 Halted 0 ms 0 KB -