Submission #143488

# Submission time Handle Problem Language Result Execution time Memory
143488 2019-08-14T09:46:31 Z darkkcyan Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
491 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
using namespace std::placeholders;

#define llong long long 
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define all(x) x.begin(), x.end()
// #define rand __rand
// mt19937 rng(chrono::system_clock::now().time_since_epoch().count());  // or mt19937_64
// template<class T = int> T rand(T range = numeric_limits<T>::max()) {
    // return (T)(rng() % range);
// }

#define maxl 20
#define maxn (1 << maxl)
#define maxq 1000101
int l, n, q;
int toxic[maxn];
pair<string, int*> queries[maxq];
int ans[maxq];

template<class ToxicIter, class QueryIter>
void solve(int level, ToxicIter beg_tox, ToxicIter end_tox, QueryIter beg_que, QueryIter end_que) {
    if (beg_que == end_que) return ;
    if (level == l) {
        assert(distance(beg_tox, end_tox) == 1);
        for (auto i = beg_que; i != end_que; ++i)
            *(i->yy) = *beg_tox;
        return ;
    }

    auto oneIter = beg_que, questionIter = end_que;
    for (auto i = beg_que; i != questionIter; ) {
        if (i->xx[level] == '?') swap(*i, *--questionIter);
        else if (i->xx[level] == '0') swap(*(i++), *(oneIter++));
        else ++i;
    }

    ToxicIter mid_tox = beg_tox;
    advance(mid_tox, distance(beg_tox, end_tox) / 2);

    solve(level + 1, beg_tox, mid_tox, beg_que, oneIter);
    solve(level + 1, mid_tox, end_tox, oneIter, questionIter);

    for (auto i = beg_tox, f = mid_tox; f != end_tox; ++i, ++f)
        *i += *f;

    solve(level + 1, beg_tox, mid_tox, questionIter, end_que);

    for (auto i = beg_tox, f = mid_tox; f != end_tox; ++i, ++f)
        *i -= *f;
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> l >> q;
    n = 1 << l;
    {
        string s; cin >> s;
        rep(i, n) toxic[i] = s[i] - '0';
    }

    rep(i, q) {
        cin >> queries[i].xx;
        queries[i].yy = ans + i;
    }

    solve(0, toxic, toxic + n, queries, queries + q);

    rep(i, q) cout << ans[i] << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 39544 KB Output is correct
2 Correct 43 ms 39544 KB Output is correct
3 Correct 38 ms 39660 KB Output is correct
4 Correct 37 ms 39544 KB Output is correct
5 Correct 38 ms 39544 KB Output is correct
6 Correct 37 ms 39544 KB Output is correct
7 Correct 38 ms 39536 KB Output is correct
8 Correct 38 ms 39544 KB Output is correct
9 Correct 38 ms 39560 KB Output is correct
10 Correct 38 ms 39516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 39544 KB Output is correct
2 Correct 43 ms 39544 KB Output is correct
3 Correct 38 ms 39660 KB Output is correct
4 Correct 37 ms 39544 KB Output is correct
5 Correct 38 ms 39544 KB Output is correct
6 Correct 37 ms 39544 KB Output is correct
7 Correct 38 ms 39536 KB Output is correct
8 Correct 38 ms 39544 KB Output is correct
9 Correct 38 ms 39560 KB Output is correct
10 Correct 38 ms 39516 KB Output is correct
11 Correct 310 ms 48612 KB Output is correct
12 Correct 353 ms 48084 KB Output is correct
13 Correct 339 ms 47480 KB Output is correct
14 Correct 334 ms 47460 KB Output is correct
15 Correct 342 ms 48604 KB Output is correct
16 Correct 348 ms 47624 KB Output is correct
17 Correct 365 ms 47580 KB Output is correct
18 Correct 288 ms 49464 KB Output is correct
19 Correct 337 ms 46548 KB Output is correct
20 Correct 325 ms 48120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 39544 KB Output is correct
2 Correct 43 ms 39544 KB Output is correct
3 Correct 38 ms 39660 KB Output is correct
4 Correct 37 ms 39544 KB Output is correct
5 Correct 38 ms 39544 KB Output is correct
6 Correct 37 ms 39544 KB Output is correct
7 Correct 38 ms 39536 KB Output is correct
8 Correct 38 ms 39544 KB Output is correct
9 Correct 38 ms 39560 KB Output is correct
10 Correct 38 ms 39516 KB Output is correct
11 Correct 310 ms 48612 KB Output is correct
12 Correct 353 ms 48084 KB Output is correct
13 Correct 339 ms 47480 KB Output is correct
14 Correct 334 ms 47460 KB Output is correct
15 Correct 342 ms 48604 KB Output is correct
16 Correct 348 ms 47624 KB Output is correct
17 Correct 365 ms 47580 KB Output is correct
18 Correct 288 ms 49464 KB Output is correct
19 Correct 337 ms 46548 KB Output is correct
20 Correct 325 ms 48120 KB Output is correct
21 Correct 358 ms 48572 KB Output is correct
22 Correct 395 ms 48648 KB Output is correct
23 Correct 418 ms 47708 KB Output is correct
24 Correct 388 ms 47720 KB Output is correct
25 Correct 390 ms 49732 KB Output is correct
26 Correct 423 ms 48120 KB Output is correct
27 Correct 491 ms 48120 KB Output is correct
28 Correct 320 ms 50552 KB Output is correct
29 Correct 339 ms 46584 KB Output is correct
30 Correct 358 ms 48760 KB Output is correct
31 Correct 432 ms 48632 KB Output is correct
32 Correct 391 ms 48504 KB Output is correct
33 Correct 353 ms 47420 KB Output is correct
34 Correct 428 ms 47608 KB Output is correct
35 Correct 484 ms 48024 KB Output is correct
36 Correct 261 ms 46524 KB Output is correct
37 Correct 367 ms 48704 KB Output is correct
38 Correct 363 ms 46588 KB Output is correct
39 Correct 388 ms 47736 KB Output is correct
40 Correct 382 ms 47560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 39544 KB Output is correct
2 Correct 43 ms 39544 KB Output is correct
3 Correct 38 ms 39660 KB Output is correct
4 Correct 37 ms 39544 KB Output is correct
5 Correct 38 ms 39544 KB Output is correct
6 Correct 37 ms 39544 KB Output is correct
7 Correct 38 ms 39536 KB Output is correct
8 Correct 38 ms 39544 KB Output is correct
9 Correct 38 ms 39560 KB Output is correct
10 Correct 38 ms 39516 KB Output is correct
11 Correct 91 ms 48264 KB Output is correct
12 Correct 95 ms 48132 KB Output is correct
13 Correct 227 ms 48136 KB Output is correct
14 Correct 249 ms 48180 KB Output is correct
15 Correct 175 ms 48260 KB Output is correct
16 Correct 264 ms 48196 KB Output is correct
17 Correct 258 ms 48136 KB Output is correct
18 Correct 68 ms 48388 KB Output is correct
19 Correct 92 ms 47988 KB Output is correct
20 Correct 92 ms 48260 KB Output is correct
21 Correct 248 ms 48224 KB Output is correct
22 Correct 248 ms 48132 KB Output is correct
23 Correct 170 ms 48004 KB Output is correct
24 Correct 250 ms 48132 KB Output is correct
25 Correct 259 ms 48148 KB Output is correct
26 Correct 62 ms 48072 KB Output is correct
27 Correct 95 ms 48128 KB Output is correct
28 Correct 92 ms 48004 KB Output is correct
29 Correct 224 ms 48104 KB Output is correct
30 Correct 250 ms 48108 KB Output is correct
31 Correct 177 ms 48132 KB Output is correct
32 Correct 253 ms 48136 KB Output is correct
33 Correct 257 ms 48104 KB Output is correct
34 Correct 66 ms 48004 KB Output is correct
35 Correct 234 ms 48132 KB Output is correct
36 Correct 234 ms 48132 KB Output is correct
37 Correct 237 ms 48132 KB Output is correct
38 Correct 249 ms 48132 KB Output is correct
39 Correct 235 ms 48260 KB Output is correct
40 Correct 236 ms 48092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 39544 KB Output is correct
2 Correct 43 ms 39544 KB Output is correct
3 Correct 38 ms 39660 KB Output is correct
4 Correct 37 ms 39544 KB Output is correct
5 Correct 38 ms 39544 KB Output is correct
6 Correct 37 ms 39544 KB Output is correct
7 Correct 38 ms 39536 KB Output is correct
8 Correct 38 ms 39544 KB Output is correct
9 Correct 38 ms 39560 KB Output is correct
10 Correct 38 ms 39516 KB Output is correct
11 Correct 310 ms 48612 KB Output is correct
12 Correct 353 ms 48084 KB Output is correct
13 Correct 339 ms 47480 KB Output is correct
14 Correct 334 ms 47460 KB Output is correct
15 Correct 342 ms 48604 KB Output is correct
16 Correct 348 ms 47624 KB Output is correct
17 Correct 365 ms 47580 KB Output is correct
18 Correct 288 ms 49464 KB Output is correct
19 Correct 337 ms 46548 KB Output is correct
20 Correct 325 ms 48120 KB Output is correct
21 Correct 358 ms 48572 KB Output is correct
22 Correct 395 ms 48648 KB Output is correct
23 Correct 418 ms 47708 KB Output is correct
24 Correct 388 ms 47720 KB Output is correct
25 Correct 390 ms 49732 KB Output is correct
26 Correct 423 ms 48120 KB Output is correct
27 Correct 491 ms 48120 KB Output is correct
28 Correct 320 ms 50552 KB Output is correct
29 Correct 339 ms 46584 KB Output is correct
30 Correct 358 ms 48760 KB Output is correct
31 Correct 432 ms 48632 KB Output is correct
32 Correct 391 ms 48504 KB Output is correct
33 Correct 353 ms 47420 KB Output is correct
34 Correct 428 ms 47608 KB Output is correct
35 Correct 484 ms 48024 KB Output is correct
36 Correct 261 ms 46524 KB Output is correct
37 Correct 367 ms 48704 KB Output is correct
38 Correct 363 ms 46588 KB Output is correct
39 Correct 388 ms 47736 KB Output is correct
40 Correct 382 ms 47560 KB Output is correct
41 Correct 91 ms 48264 KB Output is correct
42 Correct 95 ms 48132 KB Output is correct
43 Correct 227 ms 48136 KB Output is correct
44 Correct 249 ms 48180 KB Output is correct
45 Correct 175 ms 48260 KB Output is correct
46 Correct 264 ms 48196 KB Output is correct
47 Correct 258 ms 48136 KB Output is correct
48 Correct 68 ms 48388 KB Output is correct
49 Correct 92 ms 47988 KB Output is correct
50 Correct 92 ms 48260 KB Output is correct
51 Correct 248 ms 48224 KB Output is correct
52 Correct 248 ms 48132 KB Output is correct
53 Correct 170 ms 48004 KB Output is correct
54 Correct 250 ms 48132 KB Output is correct
55 Correct 259 ms 48148 KB Output is correct
56 Correct 62 ms 48072 KB Output is correct
57 Correct 95 ms 48128 KB Output is correct
58 Correct 92 ms 48004 KB Output is correct
59 Correct 224 ms 48104 KB Output is correct
60 Correct 250 ms 48108 KB Output is correct
61 Correct 177 ms 48132 KB Output is correct
62 Correct 253 ms 48136 KB Output is correct
63 Correct 257 ms 48104 KB Output is correct
64 Correct 66 ms 48004 KB Output is correct
65 Correct 234 ms 48132 KB Output is correct
66 Correct 234 ms 48132 KB Output is correct
67 Correct 237 ms 48132 KB Output is correct
68 Correct 249 ms 48132 KB Output is correct
69 Correct 235 ms 48260 KB Output is correct
70 Correct 236 ms 48092 KB Output is correct
71 Runtime error 141 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
72 Halted 0 ms 0 KB -