Submission #873278

# Submission time Handle Problem Language Result Execution time Memory
873278 2023-11-14T18:11:04 Z garam1732 Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
807 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];

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

    int a = s;
    vector<int> w, u;
    for(a = s; a <= e; a++) {
        if(qry[a].s[x] != '0') break;
    }

    for(int i = 0; i < v.size(); i++) {
        if(2*i < v.size()) w.push_back(v[i]);
        else u.push_back(v[i]);
    }

    solve(w, s, a-1, x+1);

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

    solve(u, s, a-1, x+1);

    s = a;
    vector<int> t;
    for(int i = 0; 2*i<v.size(); i++) t.push_back(v[i]+v[i+v.size()/2]);
    solve(t, s, e, x+1);
}

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

    int l, 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(v, 0, q-1, 0);

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

Compilation message

snake_escaping.cpp: In function 'void solve(std::vector<int>&, int, int, int)':
snake_escaping.cpp:28:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(x == qry[e].s.size()) {
      |        ~~^~~~~~~~~~~~~~~~~~
snake_escaping.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i = 0; i < v.size(); i++) {
      |                    ~~^~~~~~~~~~
snake_escaping.cpp:40:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if(2*i < v.size()) w.push_back(v[i]);
      |            ~~~~^~~~~~~~~~
snake_escaping.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 0; 2*i<v.size(); i++) t.push_back(v[i]+v[i+v.size()/2]);
      |                    ~~~^~~~~~~~~
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i = 0; i < s.size(); i++) v.push_back(s[i]-'0');
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 41304 KB Output is correct
2 Correct 9 ms 41308 KB Output is correct
3 Correct 11 ms 41308 KB Output is correct
4 Correct 9 ms 41308 KB Output is correct
5 Correct 9 ms 41308 KB Output is correct
6 Correct 10 ms 41308 KB Output is correct
7 Correct 10 ms 41308 KB Output is correct
8 Correct 9 ms 41304 KB Output is correct
9 Correct 10 ms 41304 KB Output is correct
10 Correct 9 ms 41304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 41304 KB Output is correct
2 Correct 9 ms 41308 KB Output is correct
3 Correct 11 ms 41308 KB Output is correct
4 Correct 9 ms 41308 KB Output is correct
5 Correct 9 ms 41308 KB Output is correct
6 Correct 10 ms 41308 KB Output is correct
7 Correct 10 ms 41308 KB Output is correct
8 Correct 9 ms 41304 KB Output is correct
9 Correct 10 ms 41304 KB Output is correct
10 Correct 9 ms 41304 KB Output is correct
11 Correct 572 ms 58220 KB Output is correct
12 Correct 600 ms 57936 KB Output is correct
13 Correct 616 ms 57400 KB Output is correct
14 Correct 586 ms 57172 KB Output is correct
15 Correct 600 ms 58104 KB Output is correct
16 Correct 636 ms 57292 KB Output is correct
17 Correct 648 ms 57264 KB Output is correct
18 Correct 505 ms 59128 KB Output is correct
19 Correct 573 ms 56148 KB Output is correct
20 Correct 599 ms 57908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 41304 KB Output is correct
2 Correct 9 ms 41308 KB Output is correct
3 Correct 11 ms 41308 KB Output is correct
4 Correct 9 ms 41308 KB Output is correct
5 Correct 9 ms 41308 KB Output is correct
6 Correct 10 ms 41308 KB Output is correct
7 Correct 10 ms 41308 KB Output is correct
8 Correct 9 ms 41304 KB Output is correct
9 Correct 10 ms 41304 KB Output is correct
10 Correct 9 ms 41304 KB Output is correct
11 Correct 572 ms 58220 KB Output is correct
12 Correct 600 ms 57936 KB Output is correct
13 Correct 616 ms 57400 KB Output is correct
14 Correct 586 ms 57172 KB Output is correct
15 Correct 600 ms 58104 KB Output is correct
16 Correct 636 ms 57292 KB Output is correct
17 Correct 648 ms 57264 KB Output is correct
18 Correct 505 ms 59128 KB Output is correct
19 Correct 573 ms 56148 KB Output is correct
20 Correct 599 ms 57908 KB Output is correct
21 Correct 640 ms 61180 KB Output is correct
22 Correct 638 ms 61428 KB Output is correct
23 Correct 741 ms 60340 KB Output is correct
24 Correct 704 ms 60152 KB Output is correct
25 Correct 692 ms 62200 KB Output is correct
26 Correct 757 ms 60916 KB Output is correct
27 Correct 791 ms 60744 KB Output is correct
28 Correct 514 ms 63224 KB Output is correct
29 Correct 613 ms 59272 KB Output is correct
30 Correct 651 ms 61380 KB Output is correct
31 Correct 766 ms 61244 KB Output is correct
32 Correct 699 ms 61116 KB Output is correct
33 Correct 664 ms 60224 KB Output is correct
34 Correct 807 ms 60164 KB Output is correct
35 Correct 805 ms 60532 KB Output is correct
36 Correct 545 ms 59140 KB Output is correct
37 Correct 604 ms 61180 KB Output is correct
38 Correct 625 ms 59144 KB Output is correct
39 Correct 742 ms 60412 KB Output is correct
40 Correct 706 ms 60152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 41304 KB Output is correct
2 Correct 9 ms 41308 KB Output is correct
3 Correct 11 ms 41308 KB Output is correct
4 Correct 9 ms 41308 KB Output is correct
5 Correct 9 ms 41308 KB Output is correct
6 Correct 10 ms 41308 KB Output is correct
7 Correct 10 ms 41308 KB Output is correct
8 Correct 9 ms 41304 KB Output is correct
9 Correct 10 ms 41304 KB Output is correct
10 Correct 9 ms 41304 KB Output is correct
11 Correct 172 ms 65424 KB Output is correct
12 Correct 181 ms 65232 KB Output is correct
13 Correct 564 ms 65132 KB Output is correct
14 Correct 586 ms 65508 KB Output is correct
15 Correct 401 ms 65416 KB Output is correct
16 Correct 598 ms 65348 KB Output is correct
17 Correct 605 ms 65264 KB Output is correct
18 Correct 63 ms 65508 KB Output is correct
19 Correct 157 ms 64384 KB Output is correct
20 Correct 163 ms 65328 KB Output is correct
21 Correct 544 ms 65100 KB Output is correct
22 Correct 652 ms 65256 KB Output is correct
23 Correct 389 ms 65120 KB Output is correct
24 Correct 606 ms 65252 KB Output is correct
25 Correct 622 ms 65388 KB Output is correct
26 Correct 63 ms 63460 KB Output is correct
27 Correct 154 ms 65160 KB Output is correct
28 Correct 167 ms 63376 KB Output is correct
29 Correct 535 ms 65388 KB Output is correct
30 Correct 604 ms 65424 KB Output is correct
31 Correct 403 ms 65256 KB Output is correct
32 Correct 620 ms 65396 KB Output is correct
33 Correct 629 ms 65380 KB Output is correct
34 Correct 63 ms 63208 KB Output is correct
35 Correct 559 ms 65360 KB Output is correct
36 Correct 543 ms 65360 KB Output is correct
37 Correct 561 ms 65256 KB Output is correct
38 Correct 545 ms 65228 KB Output is correct
39 Correct 550 ms 65480 KB Output is correct
40 Correct 591 ms 65252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 41304 KB Output is correct
2 Correct 9 ms 41308 KB Output is correct
3 Correct 11 ms 41308 KB Output is correct
4 Correct 9 ms 41308 KB Output is correct
5 Correct 9 ms 41308 KB Output is correct
6 Correct 10 ms 41308 KB Output is correct
7 Correct 10 ms 41308 KB Output is correct
8 Correct 9 ms 41304 KB Output is correct
9 Correct 10 ms 41304 KB Output is correct
10 Correct 9 ms 41304 KB Output is correct
11 Correct 572 ms 58220 KB Output is correct
12 Correct 600 ms 57936 KB Output is correct
13 Correct 616 ms 57400 KB Output is correct
14 Correct 586 ms 57172 KB Output is correct
15 Correct 600 ms 58104 KB Output is correct
16 Correct 636 ms 57292 KB Output is correct
17 Correct 648 ms 57264 KB Output is correct
18 Correct 505 ms 59128 KB Output is correct
19 Correct 573 ms 56148 KB Output is correct
20 Correct 599 ms 57908 KB Output is correct
21 Correct 640 ms 61180 KB Output is correct
22 Correct 638 ms 61428 KB Output is correct
23 Correct 741 ms 60340 KB Output is correct
24 Correct 704 ms 60152 KB Output is correct
25 Correct 692 ms 62200 KB Output is correct
26 Correct 757 ms 60916 KB Output is correct
27 Correct 791 ms 60744 KB Output is correct
28 Correct 514 ms 63224 KB Output is correct
29 Correct 613 ms 59272 KB Output is correct
30 Correct 651 ms 61380 KB Output is correct
31 Correct 766 ms 61244 KB Output is correct
32 Correct 699 ms 61116 KB Output is correct
33 Correct 664 ms 60224 KB Output is correct
34 Correct 807 ms 60164 KB Output is correct
35 Correct 805 ms 60532 KB Output is correct
36 Correct 545 ms 59140 KB Output is correct
37 Correct 604 ms 61180 KB Output is correct
38 Correct 625 ms 59144 KB Output is correct
39 Correct 742 ms 60412 KB Output is correct
40 Correct 706 ms 60152 KB Output is correct
41 Correct 172 ms 65424 KB Output is correct
42 Correct 181 ms 65232 KB Output is correct
43 Correct 564 ms 65132 KB Output is correct
44 Correct 586 ms 65508 KB Output is correct
45 Correct 401 ms 65416 KB Output is correct
46 Correct 598 ms 65348 KB Output is correct
47 Correct 605 ms 65264 KB Output is correct
48 Correct 63 ms 65508 KB Output is correct
49 Correct 157 ms 64384 KB Output is correct
50 Correct 163 ms 65328 KB Output is correct
51 Correct 544 ms 65100 KB Output is correct
52 Correct 652 ms 65256 KB Output is correct
53 Correct 389 ms 65120 KB Output is correct
54 Correct 606 ms 65252 KB Output is correct
55 Correct 622 ms 65388 KB Output is correct
56 Correct 63 ms 63460 KB Output is correct
57 Correct 154 ms 65160 KB Output is correct
58 Correct 167 ms 63376 KB Output is correct
59 Correct 535 ms 65388 KB Output is correct
60 Correct 604 ms 65424 KB Output is correct
61 Correct 403 ms 65256 KB Output is correct
62 Correct 620 ms 65396 KB Output is correct
63 Correct 629 ms 65380 KB Output is correct
64 Correct 63 ms 63208 KB Output is correct
65 Correct 559 ms 65360 KB Output is correct
66 Correct 543 ms 65360 KB Output is correct
67 Correct 561 ms 65256 KB Output is correct
68 Correct 545 ms 65228 KB Output is correct
69 Correct 550 ms 65480 KB Output is correct
70 Correct 591 ms 65252 KB Output is correct
71 Runtime error 64 ms 65536 KB Execution killed with signal 9
72 Halted 0 ms 0 KB -