답안 #873279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873279 2023-11-14T18:13:39 Z garam1732 Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
788 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;
    for(int i = 0; 2*i<v.size(); i++) v[i] += v[i+v.size()/2];
    v.resize(v.size()/2);
    solve(v, 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:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int i = 0; 2*i<v.size(); i++) 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');
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 41308 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 9 ms 41304 KB Output is correct
5 Correct 9 ms 41192 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 8 ms 41308 KB Output is correct
9 Correct 9 ms 41308 KB Output is correct
10 Correct 9 ms 41308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 41308 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 9 ms 41304 KB Output is correct
5 Correct 9 ms 41192 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 8 ms 41308 KB Output is correct
9 Correct 9 ms 41308 KB Output is correct
10 Correct 9 ms 41308 KB Output is correct
11 Correct 551 ms 47432 KB Output is correct
12 Correct 581 ms 47188 KB Output is correct
13 Correct 590 ms 46404 KB Output is correct
14 Correct 577 ms 46416 KB Output is correct
15 Correct 594 ms 47424 KB Output is correct
16 Correct 644 ms 46668 KB Output is correct
17 Correct 644 ms 46676 KB Output is correct
18 Correct 516 ms 48464 KB Output is correct
19 Correct 555 ms 45392 KB Output is correct
20 Correct 597 ms 47188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 41308 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 9 ms 41304 KB Output is correct
5 Correct 9 ms 41192 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 8 ms 41308 KB Output is correct
9 Correct 9 ms 41308 KB Output is correct
10 Correct 9 ms 41308 KB Output is correct
11 Correct 551 ms 47432 KB Output is correct
12 Correct 581 ms 47188 KB Output is correct
13 Correct 590 ms 46404 KB Output is correct
14 Correct 577 ms 46416 KB Output is correct
15 Correct 594 ms 47424 KB Output is correct
16 Correct 644 ms 46668 KB Output is correct
17 Correct 644 ms 46676 KB Output is correct
18 Correct 516 ms 48464 KB Output is correct
19 Correct 555 ms 45392 KB Output is correct
20 Correct 597 ms 47188 KB Output is correct
21 Correct 586 ms 47492 KB Output is correct
22 Correct 611 ms 47752 KB Output is correct
23 Correct 712 ms 46716 KB Output is correct
24 Correct 695 ms 46476 KB Output is correct
25 Correct 665 ms 48516 KB Output is correct
26 Correct 715 ms 46996 KB Output is correct
27 Correct 781 ms 47184 KB Output is correct
28 Correct 496 ms 49544 KB Output is correct
29 Correct 596 ms 45516 KB Output is correct
30 Correct 608 ms 47700 KB Output is correct
31 Correct 777 ms 47440 KB Output is correct
32 Correct 692 ms 47492 KB Output is correct
33 Correct 648 ms 46468 KB Output is correct
34 Correct 740 ms 46476 KB Output is correct
35 Correct 788 ms 47132 KB Output is correct
36 Correct 520 ms 45648 KB Output is correct
37 Correct 589 ms 47496 KB Output is correct
38 Correct 617 ms 45456 KB Output is correct
39 Correct 720 ms 46660 KB Output is correct
40 Correct 666 ms 46416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 41308 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 9 ms 41304 KB Output is correct
5 Correct 9 ms 41192 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 8 ms 41308 KB Output is correct
9 Correct 9 ms 41308 KB Output is correct
10 Correct 9 ms 41308 KB Output is correct
11 Correct 132 ms 59200 KB Output is correct
12 Correct 143 ms 59284 KB Output is correct
13 Correct 479 ms 59276 KB Output is correct
14 Correct 487 ms 59364 KB Output is correct
15 Correct 320 ms 59452 KB Output is correct
16 Correct 515 ms 59296 KB Output is correct
17 Correct 487 ms 59364 KB Output is correct
18 Correct 60 ms 59544 KB Output is correct
19 Correct 141 ms 59548 KB Output is correct
20 Correct 146 ms 59368 KB Output is correct
21 Correct 439 ms 59204 KB Output is correct
22 Correct 512 ms 59200 KB Output is correct
23 Correct 325 ms 59508 KB Output is correct
24 Correct 538 ms 59364 KB Output is correct
25 Correct 509 ms 59196 KB Output is correct
26 Correct 75 ms 59108 KB Output is correct
27 Correct 143 ms 59284 KB Output is correct
28 Correct 138 ms 59108 KB Output is correct
29 Correct 428 ms 59368 KB Output is correct
30 Correct 500 ms 59196 KB Output is correct
31 Correct 330 ms 59276 KB Output is correct
32 Correct 501 ms 59200 KB Output is correct
33 Correct 576 ms 59416 KB Output is correct
34 Correct 60 ms 59108 KB Output is correct
35 Correct 476 ms 59196 KB Output is correct
36 Correct 435 ms 59200 KB Output is correct
37 Correct 459 ms 59204 KB Output is correct
38 Correct 440 ms 59232 KB Output is correct
39 Correct 472 ms 59276 KB Output is correct
40 Correct 430 ms 59368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 41308 KB Output is correct
2 Correct 10 ms 41308 KB Output is correct
3 Correct 9 ms 41308 KB Output is correct
4 Correct 9 ms 41304 KB Output is correct
5 Correct 9 ms 41192 KB Output is correct
6 Correct 9 ms 41308 KB Output is correct
7 Correct 9 ms 41308 KB Output is correct
8 Correct 8 ms 41308 KB Output is correct
9 Correct 9 ms 41308 KB Output is correct
10 Correct 9 ms 41308 KB Output is correct
11 Correct 551 ms 47432 KB Output is correct
12 Correct 581 ms 47188 KB Output is correct
13 Correct 590 ms 46404 KB Output is correct
14 Correct 577 ms 46416 KB Output is correct
15 Correct 594 ms 47424 KB Output is correct
16 Correct 644 ms 46668 KB Output is correct
17 Correct 644 ms 46676 KB Output is correct
18 Correct 516 ms 48464 KB Output is correct
19 Correct 555 ms 45392 KB Output is correct
20 Correct 597 ms 47188 KB Output is correct
21 Correct 586 ms 47492 KB Output is correct
22 Correct 611 ms 47752 KB Output is correct
23 Correct 712 ms 46716 KB Output is correct
24 Correct 695 ms 46476 KB Output is correct
25 Correct 665 ms 48516 KB Output is correct
26 Correct 715 ms 46996 KB Output is correct
27 Correct 781 ms 47184 KB Output is correct
28 Correct 496 ms 49544 KB Output is correct
29 Correct 596 ms 45516 KB Output is correct
30 Correct 608 ms 47700 KB Output is correct
31 Correct 777 ms 47440 KB Output is correct
32 Correct 692 ms 47492 KB Output is correct
33 Correct 648 ms 46468 KB Output is correct
34 Correct 740 ms 46476 KB Output is correct
35 Correct 788 ms 47132 KB Output is correct
36 Correct 520 ms 45648 KB Output is correct
37 Correct 589 ms 47496 KB Output is correct
38 Correct 617 ms 45456 KB Output is correct
39 Correct 720 ms 46660 KB Output is correct
40 Correct 666 ms 46416 KB Output is correct
41 Correct 132 ms 59200 KB Output is correct
42 Correct 143 ms 59284 KB Output is correct
43 Correct 479 ms 59276 KB Output is correct
44 Correct 487 ms 59364 KB Output is correct
45 Correct 320 ms 59452 KB Output is correct
46 Correct 515 ms 59296 KB Output is correct
47 Correct 487 ms 59364 KB Output is correct
48 Correct 60 ms 59544 KB Output is correct
49 Correct 141 ms 59548 KB Output is correct
50 Correct 146 ms 59368 KB Output is correct
51 Correct 439 ms 59204 KB Output is correct
52 Correct 512 ms 59200 KB Output is correct
53 Correct 325 ms 59508 KB Output is correct
54 Correct 538 ms 59364 KB Output is correct
55 Correct 509 ms 59196 KB Output is correct
56 Correct 75 ms 59108 KB Output is correct
57 Correct 143 ms 59284 KB Output is correct
58 Correct 138 ms 59108 KB Output is correct
59 Correct 428 ms 59368 KB Output is correct
60 Correct 500 ms 59196 KB Output is correct
61 Correct 330 ms 59276 KB Output is correct
62 Correct 501 ms 59200 KB Output is correct
63 Correct 576 ms 59416 KB Output is correct
64 Correct 60 ms 59108 KB Output is correct
65 Correct 476 ms 59196 KB Output is correct
66 Correct 435 ms 59200 KB Output is correct
67 Correct 459 ms 59204 KB Output is correct
68 Correct 440 ms 59232 KB Output is correct
69 Correct 472 ms 59276 KB Output is correct
70 Correct 430 ms 59368 KB Output is correct
71 Runtime error 63 ms 65536 KB Execution killed with signal 9
72 Halted 0 ms 0 KB -