Submission #873406

# Submission time Handle Problem Language Result Execution time Memory
873406 2023-11-15T02:58:51 Z garam1732 Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1401 ms 53508 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/5;
const int MOD = 1e9+7;

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

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');
    }

    int sz = 5;
    for(int i = 0; i < sz; i++) {
        int s = q*i/sz+1, e = q*(i+1)/sz;

        for(int j = s; j <= e; j++) {
            cin >> qry[j-s].s; qry[j-s].x = j-s;
        }

        for(int j = 0; j <= e-s; j++) {
            qry[j].v = 0;
            for(int k = 0; k < l; k++) {
                qry[j].v *= 3;
                if(qry[j].s[k] == '1') qry[j].v += 1;
                else if(qry[j].s[k] == '?') qry[j].v += 2;
            }
        }

        sort(qry, qry+e-s+1, [](Query &a, Query &b){return a.v<b.v;});

        solve(0, e-s, 0, (1<<l)-1, 0);

        for(int j = 0; j <= e-s; j++) cout << ans[j] << 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;
      |                      ~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 3 ms 10332 KB Output is correct
4 Correct 3 ms 10332 KB Output is correct
5 Correct 4 ms 10332 KB Output is correct
6 Correct 3 ms 10332 KB Output is correct
7 Correct 3 ms 10332 KB Output is correct
8 Correct 2 ms 10332 KB Output is correct
9 Correct 2 ms 10420 KB Output is correct
10 Correct 3 ms 10332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 3 ms 10332 KB Output is correct
4 Correct 3 ms 10332 KB Output is correct
5 Correct 4 ms 10332 KB Output is correct
6 Correct 3 ms 10332 KB Output is correct
7 Correct 3 ms 10332 KB Output is correct
8 Correct 2 ms 10332 KB Output is correct
9 Correct 2 ms 10420 KB Output is correct
10 Correct 3 ms 10332 KB Output is correct
11 Correct 257 ms 14632 KB Output is correct
12 Correct 259 ms 14304 KB Output is correct
13 Correct 280 ms 13404 KB Output is correct
14 Correct 279 ms 13396 KB Output is correct
15 Correct 255 ms 14676 KB Output is correct
16 Correct 289 ms 13564 KB Output is correct
17 Correct 319 ms 13596 KB Output is correct
18 Correct 195 ms 15440 KB Output is correct
19 Correct 245 ms 12488 KB Output is correct
20 Correct 280 ms 14332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 3 ms 10332 KB Output is correct
4 Correct 3 ms 10332 KB Output is correct
5 Correct 4 ms 10332 KB Output is correct
6 Correct 3 ms 10332 KB Output is correct
7 Correct 3 ms 10332 KB Output is correct
8 Correct 2 ms 10332 KB Output is correct
9 Correct 2 ms 10420 KB Output is correct
10 Correct 3 ms 10332 KB Output is correct
11 Correct 257 ms 14632 KB Output is correct
12 Correct 259 ms 14304 KB Output is correct
13 Correct 280 ms 13404 KB Output is correct
14 Correct 279 ms 13396 KB Output is correct
15 Correct 255 ms 14676 KB Output is correct
16 Correct 289 ms 13564 KB Output is correct
17 Correct 319 ms 13596 KB Output is correct
18 Correct 195 ms 15440 KB Output is correct
19 Correct 245 ms 12488 KB Output is correct
20 Correct 280 ms 14332 KB Output is correct
21 Correct 268 ms 14552 KB Output is correct
22 Correct 286 ms 14676 KB Output is correct
23 Correct 331 ms 13624 KB Output is correct
24 Correct 343 ms 13836 KB Output is correct
25 Correct 309 ms 15700 KB Output is correct
26 Correct 358 ms 14180 KB Output is correct
27 Correct 370 ms 14036 KB Output is correct
28 Correct 209 ms 16496 KB Output is correct
29 Correct 276 ms 12540 KB Output is correct
30 Correct 286 ms 14780 KB Output is correct
31 Correct 338 ms 14672 KB Output is correct
32 Correct 330 ms 14676 KB Output is correct
33 Correct 337 ms 13516 KB Output is correct
34 Correct 346 ms 13756 KB Output is correct
35 Correct 369 ms 14108 KB Output is correct
36 Correct 203 ms 12556 KB Output is correct
37 Correct 280 ms 14672 KB Output is correct
38 Correct 290 ms 12552 KB Output is correct
39 Correct 351 ms 13628 KB Output is correct
40 Correct 342 ms 13672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 3 ms 10332 KB Output is correct
4 Correct 3 ms 10332 KB Output is correct
5 Correct 4 ms 10332 KB Output is correct
6 Correct 3 ms 10332 KB Output is correct
7 Correct 3 ms 10332 KB Output is correct
8 Correct 2 ms 10332 KB Output is correct
9 Correct 2 ms 10420 KB Output is correct
10 Correct 3 ms 10332 KB Output is correct
11 Correct 71 ms 16340 KB Output is correct
12 Correct 76 ms 16340 KB Output is correct
13 Correct 241 ms 16080 KB Output is correct
14 Correct 268 ms 15572 KB Output is correct
15 Correct 181 ms 15824 KB Output is correct
16 Correct 297 ms 15572 KB Output is correct
17 Correct 276 ms 15828 KB Output is correct
18 Correct 28 ms 15308 KB Output is correct
19 Correct 69 ms 16596 KB Output is correct
20 Correct 77 ms 16592 KB Output is correct
21 Correct 247 ms 15828 KB Output is correct
22 Correct 281 ms 16592 KB Output is correct
23 Correct 180 ms 15312 KB Output is correct
24 Correct 278 ms 15316 KB Output is correct
25 Correct 283 ms 15088 KB Output is correct
26 Correct 30 ms 16336 KB Output is correct
27 Correct 70 ms 15292 KB Output is correct
28 Correct 75 ms 15572 KB Output is correct
29 Correct 253 ms 15572 KB Output is correct
30 Correct 276 ms 15052 KB Output is correct
31 Correct 188 ms 16336 KB Output is correct
32 Correct 293 ms 15568 KB Output is correct
33 Correct 285 ms 15312 KB Output is correct
34 Correct 30 ms 16340 KB Output is correct
35 Correct 250 ms 15828 KB Output is correct
36 Correct 257 ms 16336 KB Output is correct
37 Correct 263 ms 16348 KB Output is correct
38 Correct 250 ms 16596 KB Output is correct
39 Correct 261 ms 16336 KB Output is correct
40 Correct 248 ms 16340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 3 ms 10332 KB Output is correct
4 Correct 3 ms 10332 KB Output is correct
5 Correct 4 ms 10332 KB Output is correct
6 Correct 3 ms 10332 KB Output is correct
7 Correct 3 ms 10332 KB Output is correct
8 Correct 2 ms 10332 KB Output is correct
9 Correct 2 ms 10420 KB Output is correct
10 Correct 3 ms 10332 KB Output is correct
11 Correct 257 ms 14632 KB Output is correct
12 Correct 259 ms 14304 KB Output is correct
13 Correct 280 ms 13404 KB Output is correct
14 Correct 279 ms 13396 KB Output is correct
15 Correct 255 ms 14676 KB Output is correct
16 Correct 289 ms 13564 KB Output is correct
17 Correct 319 ms 13596 KB Output is correct
18 Correct 195 ms 15440 KB Output is correct
19 Correct 245 ms 12488 KB Output is correct
20 Correct 280 ms 14332 KB Output is correct
21 Correct 268 ms 14552 KB Output is correct
22 Correct 286 ms 14676 KB Output is correct
23 Correct 331 ms 13624 KB Output is correct
24 Correct 343 ms 13836 KB Output is correct
25 Correct 309 ms 15700 KB Output is correct
26 Correct 358 ms 14180 KB Output is correct
27 Correct 370 ms 14036 KB Output is correct
28 Correct 209 ms 16496 KB Output is correct
29 Correct 276 ms 12540 KB Output is correct
30 Correct 286 ms 14780 KB Output is correct
31 Correct 338 ms 14672 KB Output is correct
32 Correct 330 ms 14676 KB Output is correct
33 Correct 337 ms 13516 KB Output is correct
34 Correct 346 ms 13756 KB Output is correct
35 Correct 369 ms 14108 KB Output is correct
36 Correct 203 ms 12556 KB Output is correct
37 Correct 280 ms 14672 KB Output is correct
38 Correct 290 ms 12552 KB Output is correct
39 Correct 351 ms 13628 KB Output is correct
40 Correct 342 ms 13672 KB Output is correct
41 Correct 71 ms 16340 KB Output is correct
42 Correct 76 ms 16340 KB Output is correct
43 Correct 241 ms 16080 KB Output is correct
44 Correct 268 ms 15572 KB Output is correct
45 Correct 181 ms 15824 KB Output is correct
46 Correct 297 ms 15572 KB Output is correct
47 Correct 276 ms 15828 KB Output is correct
48 Correct 28 ms 15308 KB Output is correct
49 Correct 69 ms 16596 KB Output is correct
50 Correct 77 ms 16592 KB Output is correct
51 Correct 247 ms 15828 KB Output is correct
52 Correct 281 ms 16592 KB Output is correct
53 Correct 180 ms 15312 KB Output is correct
54 Correct 278 ms 15316 KB Output is correct
55 Correct 283 ms 15088 KB Output is correct
56 Correct 30 ms 16336 KB Output is correct
57 Correct 70 ms 15292 KB Output is correct
58 Correct 75 ms 15572 KB Output is correct
59 Correct 253 ms 15572 KB Output is correct
60 Correct 276 ms 15052 KB Output is correct
61 Correct 188 ms 16336 KB Output is correct
62 Correct 293 ms 15568 KB Output is correct
63 Correct 285 ms 15312 KB Output is correct
64 Correct 30 ms 16340 KB Output is correct
65 Correct 250 ms 15828 KB Output is correct
66 Correct 257 ms 16336 KB Output is correct
67 Correct 263 ms 16348 KB Output is correct
68 Correct 250 ms 16596 KB Output is correct
69 Correct 261 ms 16336 KB Output is correct
70 Correct 248 ms 16340 KB Output is correct
71 Correct 529 ms 32864 KB Output is correct
72 Correct 547 ms 41756 KB Output is correct
73 Correct 1213 ms 36796 KB Output is correct
74 Correct 1340 ms 49528 KB Output is correct
75 Correct 900 ms 51500 KB Output is correct
76 Correct 1383 ms 49892 KB Output is correct
77 Correct 1385 ms 49796 KB Output is correct
78 Correct 256 ms 53508 KB Output is correct
79 Correct 531 ms 47748 KB Output is correct
80 Correct 539 ms 50624 KB Output is correct
81 Correct 1215 ms 50684 KB Output is correct
82 Correct 1366 ms 49648 KB Output is correct
83 Correct 939 ms 48728 KB Output is correct
84 Correct 1373 ms 49652 KB Output is correct
85 Correct 1390 ms 50040 KB Output is correct
86 Correct 347 ms 47408 KB Output is correct
87 Correct 522 ms 50544 KB Output is correct
88 Correct 585 ms 47532 KB Output is correct
89 Correct 1224 ms 49272 KB Output is correct
90 Correct 1384 ms 49788 KB Output is correct
91 Correct 890 ms 48836 KB Output is correct
92 Correct 1368 ms 49748 KB Output is correct
93 Correct 1401 ms 49856 KB Output is correct
94 Correct 349 ms 47548 KB Output is correct
95 Correct 1243 ms 49852 KB Output is correct
96 Correct 1229 ms 49904 KB Output is correct
97 Correct 1240 ms 49968 KB Output is correct
98 Correct 1230 ms 49564 KB Output is correct
99 Correct 1244 ms 49540 KB Output is correct
100 Correct 1263 ms 49764 KB Output is correct