답안 #873399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873399 2023-11-15T02:32:34 Z garam1732 Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 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/2];

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

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

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

    solve(s, a-1, l, mid, x+1);

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

    solve(s, a-1, mid+1, r, x+1);

    s = a;
    for(int i = l, j = mid+1; j <= r; i++, j++) v[i] += v[j];
    solve(s, e, l, mid, x+1);
    for(int i = l, j = mid+1; j <= r; i++, j++) v[i] -= v[j];
}

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

    int l, q; cin >> l >> q; char x;
    for(int i = 0; i < (1<<l); i++) {
        cin >> x; v.push_back(x-'0');
    }

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

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

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

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

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

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

Compilation message

snake_escaping.cpp: In function 'void solve(int, int, int, int, int)':
snake_escaping.cpp:32:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int a = s, mid = l+r>>1;
      |                      ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21596 KB Output is correct
2 Correct 4 ms 21700 KB Output is correct
3 Correct 5 ms 21596 KB Output is correct
4 Correct 5 ms 21596 KB Output is correct
5 Correct 4 ms 21596 KB Output is correct
6 Correct 4 ms 21596 KB Output is correct
7 Correct 5 ms 21596 KB Output is correct
8 Correct 4 ms 21592 KB Output is correct
9 Correct 4 ms 21596 KB Output is correct
10 Correct 6 ms 21596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21596 KB Output is correct
2 Correct 4 ms 21700 KB Output is correct
3 Correct 5 ms 21596 KB Output is correct
4 Correct 5 ms 21596 KB Output is correct
5 Correct 4 ms 21596 KB Output is correct
6 Correct 4 ms 21596 KB Output is correct
7 Correct 5 ms 21596 KB Output is correct
8 Correct 4 ms 21592 KB Output is correct
9 Correct 4 ms 21596 KB Output is correct
10 Correct 6 ms 21596 KB Output is correct
11 Correct 544 ms 27736 KB Output is correct
12 Correct 570 ms 27456 KB Output is correct
13 Correct 579 ms 26704 KB Output is correct
14 Correct 557 ms 26724 KB Output is correct
15 Correct 606 ms 27884 KB Output is correct
16 Correct 591 ms 27096 KB Output is correct
17 Correct 635 ms 26840 KB Output is correct
18 Correct 479 ms 29012 KB Output is correct
19 Correct 542 ms 25940 KB Output is correct
20 Correct 568 ms 27476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21596 KB Output is correct
2 Correct 4 ms 21700 KB Output is correct
3 Correct 5 ms 21596 KB Output is correct
4 Correct 5 ms 21596 KB Output is correct
5 Correct 4 ms 21596 KB Output is correct
6 Correct 4 ms 21596 KB Output is correct
7 Correct 5 ms 21596 KB Output is correct
8 Correct 4 ms 21592 KB Output is correct
9 Correct 4 ms 21596 KB Output is correct
10 Correct 6 ms 21596 KB Output is correct
11 Correct 544 ms 27736 KB Output is correct
12 Correct 570 ms 27456 KB Output is correct
13 Correct 579 ms 26704 KB Output is correct
14 Correct 557 ms 26724 KB Output is correct
15 Correct 606 ms 27884 KB Output is correct
16 Correct 591 ms 27096 KB Output is correct
17 Correct 635 ms 26840 KB Output is correct
18 Correct 479 ms 29012 KB Output is correct
19 Correct 542 ms 25940 KB Output is correct
20 Correct 568 ms 27476 KB Output is correct
21 Correct 572 ms 27788 KB Output is correct
22 Correct 600 ms 28116 KB Output is correct
23 Correct 680 ms 27068 KB Output is correct
24 Correct 648 ms 26840 KB Output is correct
25 Correct 635 ms 29128 KB Output is correct
26 Correct 683 ms 27408 KB Output is correct
27 Correct 695 ms 27476 KB Output is correct
28 Correct 481 ms 29828 KB Output is correct
29 Correct 579 ms 25760 KB Output is correct
30 Correct 600 ms 27940 KB Output is correct
31 Correct 660 ms 27980 KB Output is correct
32 Correct 642 ms 27984 KB Output is correct
33 Correct 646 ms 26720 KB Output is correct
34 Correct 672 ms 26896 KB Output is correct
35 Correct 710 ms 27220 KB Output is correct
36 Correct 491 ms 26048 KB Output is correct
37 Correct 582 ms 27984 KB Output is correct
38 Correct 597 ms 25936 KB Output is correct
39 Correct 664 ms 27152 KB Output is correct
40 Correct 667 ms 26960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21596 KB Output is correct
2 Correct 4 ms 21700 KB Output is correct
3 Correct 5 ms 21596 KB Output is correct
4 Correct 5 ms 21596 KB Output is correct
5 Correct 4 ms 21596 KB Output is correct
6 Correct 4 ms 21596 KB Output is correct
7 Correct 5 ms 21596 KB Output is correct
8 Correct 4 ms 21592 KB Output is correct
9 Correct 4 ms 21596 KB Output is correct
10 Correct 6 ms 21596 KB Output is correct
11 Correct 89 ms 27856 KB Output is correct
12 Correct 88 ms 27344 KB Output is correct
13 Correct 192 ms 27344 KB Output is correct
14 Correct 216 ms 27856 KB Output is correct
15 Correct 150 ms 27224 KB Output is correct
16 Correct 208 ms 27216 KB Output is correct
17 Correct 219 ms 27104 KB Output is correct
18 Correct 55 ms 27324 KB Output is correct
19 Correct 88 ms 27080 KB Output is correct
20 Correct 90 ms 27384 KB Output is correct
21 Correct 219 ms 27456 KB Output is correct
22 Correct 211 ms 27604 KB Output is correct
23 Correct 152 ms 27192 KB Output is correct
24 Correct 209 ms 27600 KB Output is correct
25 Correct 213 ms 27276 KB Output is correct
26 Correct 59 ms 27092 KB Output is correct
27 Correct 89 ms 27280 KB Output is correct
28 Correct 88 ms 27088 KB Output is correct
29 Correct 192 ms 27068 KB Output is correct
30 Correct 207 ms 27088 KB Output is correct
31 Correct 158 ms 27244 KB Output is correct
32 Correct 210 ms 27348 KB Output is correct
33 Correct 213 ms 27092 KB Output is correct
34 Correct 55 ms 27072 KB Output is correct
35 Correct 195 ms 27084 KB Output is correct
36 Correct 200 ms 27080 KB Output is correct
37 Correct 196 ms 27080 KB Output is correct
38 Correct 194 ms 27088 KB Output is correct
39 Correct 196 ms 27348 KB Output is correct
40 Correct 200 ms 27860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21596 KB Output is correct
2 Correct 4 ms 21700 KB Output is correct
3 Correct 5 ms 21596 KB Output is correct
4 Correct 5 ms 21596 KB Output is correct
5 Correct 4 ms 21596 KB Output is correct
6 Correct 4 ms 21596 KB Output is correct
7 Correct 5 ms 21596 KB Output is correct
8 Correct 4 ms 21592 KB Output is correct
9 Correct 4 ms 21596 KB Output is correct
10 Correct 6 ms 21596 KB Output is correct
11 Correct 544 ms 27736 KB Output is correct
12 Correct 570 ms 27456 KB Output is correct
13 Correct 579 ms 26704 KB Output is correct
14 Correct 557 ms 26724 KB Output is correct
15 Correct 606 ms 27884 KB Output is correct
16 Correct 591 ms 27096 KB Output is correct
17 Correct 635 ms 26840 KB Output is correct
18 Correct 479 ms 29012 KB Output is correct
19 Correct 542 ms 25940 KB Output is correct
20 Correct 568 ms 27476 KB Output is correct
21 Correct 572 ms 27788 KB Output is correct
22 Correct 600 ms 28116 KB Output is correct
23 Correct 680 ms 27068 KB Output is correct
24 Correct 648 ms 26840 KB Output is correct
25 Correct 635 ms 29128 KB Output is correct
26 Correct 683 ms 27408 KB Output is correct
27 Correct 695 ms 27476 KB Output is correct
28 Correct 481 ms 29828 KB Output is correct
29 Correct 579 ms 25760 KB Output is correct
30 Correct 600 ms 27940 KB Output is correct
31 Correct 660 ms 27980 KB Output is correct
32 Correct 642 ms 27984 KB Output is correct
33 Correct 646 ms 26720 KB Output is correct
34 Correct 672 ms 26896 KB Output is correct
35 Correct 710 ms 27220 KB Output is correct
36 Correct 491 ms 26048 KB Output is correct
37 Correct 582 ms 27984 KB Output is correct
38 Correct 597 ms 25936 KB Output is correct
39 Correct 664 ms 27152 KB Output is correct
40 Correct 667 ms 26960 KB Output is correct
41 Correct 89 ms 27856 KB Output is correct
42 Correct 88 ms 27344 KB Output is correct
43 Correct 192 ms 27344 KB Output is correct
44 Correct 216 ms 27856 KB Output is correct
45 Correct 150 ms 27224 KB Output is correct
46 Correct 208 ms 27216 KB Output is correct
47 Correct 219 ms 27104 KB Output is correct
48 Correct 55 ms 27324 KB Output is correct
49 Correct 88 ms 27080 KB Output is correct
50 Correct 90 ms 27384 KB Output is correct
51 Correct 219 ms 27456 KB Output is correct
52 Correct 211 ms 27604 KB Output is correct
53 Correct 152 ms 27192 KB Output is correct
54 Correct 209 ms 27600 KB Output is correct
55 Correct 213 ms 27276 KB Output is correct
56 Correct 59 ms 27092 KB Output is correct
57 Correct 89 ms 27280 KB Output is correct
58 Correct 88 ms 27088 KB Output is correct
59 Correct 192 ms 27068 KB Output is correct
60 Correct 207 ms 27088 KB Output is correct
61 Correct 158 ms 27244 KB Output is correct
62 Correct 210 ms 27348 KB Output is correct
63 Correct 213 ms 27092 KB Output is correct
64 Correct 55 ms 27072 KB Output is correct
65 Correct 195 ms 27084 KB Output is correct
66 Correct 200 ms 27080 KB Output is correct
67 Correct 196 ms 27080 KB Output is correct
68 Correct 194 ms 27088 KB Output is correct
69 Correct 196 ms 27348 KB Output is correct
70 Correct 200 ms 27860 KB Output is correct
71 Correct 1906 ms 65536 KB Output is correct
72 Correct 1963 ms 65536 KB Output is correct
73 Execution timed out 2099 ms 65536 KB Time limit exceeded
74 Halted 0 ms 0 KB -