Submission #713008

# Submission time Handle Problem Language Result Execution time Memory
713008 2023-03-20T19:54:05 Z piOOE Game (APIO22_game) C++17
100 / 100
1363 ms 52488 KB
#include "game.h"
#include <bits/stdc++.h>

constexpr int N = 3e5 + 7, B = 8, inf = 1e9 + 7;

int fromMe[N], toMe[N], used[2][N], n, k; //smallest from me, biggest to me

std::vector<int> adj[N], rev[N];

bool found = false;

int save[2][N], level[N];

void init(int n, int k) {
    ::n = n, ::k = k;

    for (int i = 0; i < n; ++i) {
        if (i >= k) {
            fromMe[i] = inf, toMe[i] = -inf;
        } else {
            fromMe[i] = toMe[i] = i;
        }
        level[i] = std::__lg(k);
    }

    memset(save[0], 0x3f, sizeof(save[0]));
    memset(save[1], -0x3f, sizeof(save[1]));
}

void dfs2(int v, int x);

void dfs1(int v, int x) {
    if (found || v < k || fromMe[v] <= x) {
        return;
    }

    if ((fromMe[v] >> level[v] != toMe[v] >> level[v]) && (fromMe[v] >> level[v]) <= (x >> level[v])) {
        save[0][v] = std::min(save[0][v], x);
        return;
    }

    fromMe[v] = x;

    if (fromMe[v] <= toMe[v]) {
        found = true;
        return;
    }

    if ((toMe[v] >> level[v]) == (fromMe[v] >> level[v])) {
        level[v] -= 1;
        if (save[1][v] >= 0) {
            int s = save[1][v];
            save[1][v] = -1;
            dfs2(v, s);
        }
    }


    for (int to : rev[v]) {
        dfs1(to, x);
    }
}

void dfs2(int v, int x) {
    if (found || v < k || toMe[v] >= x) {
        return;
    }

    if ((fromMe[v] >> level[v]) != (toMe[v] >> level[v]) && (toMe[v] >> level[v]) >= (x >> level[v])) {
        save[1][v] = std::max(save[1][v], x);
        return;
    }

    toMe[v] = x;

    if (fromMe[v] <= toMe[v]) {
        found = true;
        return;
    }

    if ((toMe[v] >> level[v]) == (fromMe[v] >> level[v])) {
        level[v] -= 1;
        if (save[0][v] <= k) {
            int s = save[0][v];
            save[0][v] = k + 1;
            dfs1(v, s);
        }
    }

    for (int to : adj[v]) {
        dfs2(to, x);
    }
}

int add_teleporter(int u, int v) {
    if (u < k && v < k && u >= v) {
        return 1;
    }

    adj[u].push_back(v);
    rev[v].push_back(u);

    dfs1(u, fromMe[v]);
    dfs2(v, toMe[u]);

    return found;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16720 KB Output is correct
2 Correct 9 ms 16720 KB Output is correct
3 Correct 10 ms 16720 KB Output is correct
4 Correct 9 ms 16656 KB Output is correct
5 Correct 9 ms 16720 KB Output is correct
6 Correct 9 ms 16720 KB Output is correct
7 Correct 9 ms 16720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16720 KB Output is correct
2 Correct 9 ms 16720 KB Output is correct
3 Correct 10 ms 16720 KB Output is correct
4 Correct 9 ms 16656 KB Output is correct
5 Correct 9 ms 16720 KB Output is correct
6 Correct 9 ms 16720 KB Output is correct
7 Correct 9 ms 16720 KB Output is correct
8 Correct 9 ms 16696 KB Output is correct
9 Correct 8 ms 16720 KB Output is correct
10 Correct 10 ms 16676 KB Output is correct
11 Correct 9 ms 16720 KB Output is correct
12 Correct 9 ms 16720 KB Output is correct
13 Correct 10 ms 16720 KB Output is correct
14 Correct 9 ms 16720 KB Output is correct
15 Correct 9 ms 16720 KB Output is correct
16 Correct 9 ms 16656 KB Output is correct
17 Correct 9 ms 16720 KB Output is correct
18 Correct 10 ms 16720 KB Output is correct
19 Correct 9 ms 16720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16720 KB Output is correct
2 Correct 9 ms 16720 KB Output is correct
3 Correct 10 ms 16720 KB Output is correct
4 Correct 9 ms 16656 KB Output is correct
5 Correct 9 ms 16720 KB Output is correct
6 Correct 9 ms 16720 KB Output is correct
7 Correct 9 ms 16720 KB Output is correct
8 Correct 9 ms 16696 KB Output is correct
9 Correct 8 ms 16720 KB Output is correct
10 Correct 10 ms 16676 KB Output is correct
11 Correct 9 ms 16720 KB Output is correct
12 Correct 9 ms 16720 KB Output is correct
13 Correct 10 ms 16720 KB Output is correct
14 Correct 9 ms 16720 KB Output is correct
15 Correct 9 ms 16720 KB Output is correct
16 Correct 9 ms 16656 KB Output is correct
17 Correct 9 ms 16720 KB Output is correct
18 Correct 10 ms 16720 KB Output is correct
19 Correct 9 ms 16720 KB Output is correct
20 Correct 10 ms 16780 KB Output is correct
21 Correct 9 ms 16720 KB Output is correct
22 Correct 9 ms 16708 KB Output is correct
23 Correct 10 ms 16720 KB Output is correct
24 Correct 9 ms 16848 KB Output is correct
25 Correct 13 ms 16852 KB Output is correct
26 Correct 11 ms 16848 KB Output is correct
27 Correct 11 ms 16848 KB Output is correct
28 Correct 11 ms 16784 KB Output is correct
29 Correct 12 ms 16780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16720 KB Output is correct
2 Correct 9 ms 16720 KB Output is correct
3 Correct 10 ms 16720 KB Output is correct
4 Correct 9 ms 16656 KB Output is correct
5 Correct 9 ms 16720 KB Output is correct
6 Correct 9 ms 16720 KB Output is correct
7 Correct 9 ms 16720 KB Output is correct
8 Correct 9 ms 16696 KB Output is correct
9 Correct 8 ms 16720 KB Output is correct
10 Correct 10 ms 16676 KB Output is correct
11 Correct 9 ms 16720 KB Output is correct
12 Correct 9 ms 16720 KB Output is correct
13 Correct 10 ms 16720 KB Output is correct
14 Correct 9 ms 16720 KB Output is correct
15 Correct 9 ms 16720 KB Output is correct
16 Correct 9 ms 16656 KB Output is correct
17 Correct 9 ms 16720 KB Output is correct
18 Correct 10 ms 16720 KB Output is correct
19 Correct 9 ms 16720 KB Output is correct
20 Correct 10 ms 16780 KB Output is correct
21 Correct 9 ms 16720 KB Output is correct
22 Correct 9 ms 16708 KB Output is correct
23 Correct 10 ms 16720 KB Output is correct
24 Correct 9 ms 16848 KB Output is correct
25 Correct 13 ms 16852 KB Output is correct
26 Correct 11 ms 16848 KB Output is correct
27 Correct 11 ms 16848 KB Output is correct
28 Correct 11 ms 16784 KB Output is correct
29 Correct 12 ms 16780 KB Output is correct
30 Correct 29 ms 18248 KB Output is correct
31 Correct 13 ms 17488 KB Output is correct
32 Correct 27 ms 19120 KB Output is correct
33 Correct 26 ms 18908 KB Output is correct
34 Correct 42 ms 20864 KB Output is correct
35 Correct 38 ms 19536 KB Output is correct
36 Correct 49 ms 18900 KB Output is correct
37 Correct 34 ms 18892 KB Output is correct
38 Correct 39 ms 18736 KB Output is correct
39 Correct 40 ms 18720 KB Output is correct
40 Correct 45 ms 20680 KB Output is correct
41 Correct 36 ms 19156 KB Output is correct
42 Correct 35 ms 19044 KB Output is correct
43 Correct 41 ms 19500 KB Output is correct
44 Correct 46 ms 19784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16720 KB Output is correct
2 Correct 9 ms 16720 KB Output is correct
3 Correct 10 ms 16720 KB Output is correct
4 Correct 9 ms 16656 KB Output is correct
5 Correct 9 ms 16720 KB Output is correct
6 Correct 9 ms 16720 KB Output is correct
7 Correct 9 ms 16720 KB Output is correct
8 Correct 9 ms 16696 KB Output is correct
9 Correct 8 ms 16720 KB Output is correct
10 Correct 10 ms 16676 KB Output is correct
11 Correct 9 ms 16720 KB Output is correct
12 Correct 9 ms 16720 KB Output is correct
13 Correct 10 ms 16720 KB Output is correct
14 Correct 9 ms 16720 KB Output is correct
15 Correct 9 ms 16720 KB Output is correct
16 Correct 9 ms 16656 KB Output is correct
17 Correct 9 ms 16720 KB Output is correct
18 Correct 10 ms 16720 KB Output is correct
19 Correct 9 ms 16720 KB Output is correct
20 Correct 10 ms 16780 KB Output is correct
21 Correct 9 ms 16720 KB Output is correct
22 Correct 9 ms 16708 KB Output is correct
23 Correct 10 ms 16720 KB Output is correct
24 Correct 9 ms 16848 KB Output is correct
25 Correct 13 ms 16852 KB Output is correct
26 Correct 11 ms 16848 KB Output is correct
27 Correct 11 ms 16848 KB Output is correct
28 Correct 11 ms 16784 KB Output is correct
29 Correct 12 ms 16780 KB Output is correct
30 Correct 29 ms 18248 KB Output is correct
31 Correct 13 ms 17488 KB Output is correct
32 Correct 27 ms 19120 KB Output is correct
33 Correct 26 ms 18908 KB Output is correct
34 Correct 42 ms 20864 KB Output is correct
35 Correct 38 ms 19536 KB Output is correct
36 Correct 49 ms 18900 KB Output is correct
37 Correct 34 ms 18892 KB Output is correct
38 Correct 39 ms 18736 KB Output is correct
39 Correct 40 ms 18720 KB Output is correct
40 Correct 45 ms 20680 KB Output is correct
41 Correct 36 ms 19156 KB Output is correct
42 Correct 35 ms 19044 KB Output is correct
43 Correct 41 ms 19500 KB Output is correct
44 Correct 46 ms 19784 KB Output is correct
45 Correct 228 ms 31676 KB Output is correct
46 Correct 17 ms 20720 KB Output is correct
47 Correct 17 ms 20604 KB Output is correct
48 Correct 356 ms 43004 KB Output is correct
49 Correct 300 ms 38988 KB Output is correct
50 Correct 624 ms 44320 KB Output is correct
51 Correct 666 ms 43208 KB Output is correct
52 Correct 559 ms 38908 KB Output is correct
53 Correct 800 ms 39084 KB Output is correct
54 Correct 835 ms 38640 KB Output is correct
55 Correct 1008 ms 39172 KB Output is correct
56 Correct 1174 ms 38812 KB Output is correct
57 Correct 463 ms 32824 KB Output is correct
58 Correct 473 ms 32972 KB Output is correct
59 Correct 510 ms 33128 KB Output is correct
60 Correct 516 ms 32896 KB Output is correct
61 Correct 489 ms 32604 KB Output is correct
62 Correct 522 ms 38396 KB Output is correct
63 Correct 426 ms 35020 KB Output is correct
64 Correct 1161 ms 52488 KB Output is correct
65 Correct 468 ms 37564 KB Output is correct
66 Correct 380 ms 33372 KB Output is correct
67 Correct 704 ms 42040 KB Output is correct
68 Correct 211 ms 29688 KB Output is correct
69 Correct 57 ms 23660 KB Output is correct
70 Correct 675 ms 40028 KB Output is correct
71 Correct 365 ms 32448 KB Output is correct
72 Correct 255 ms 28372 KB Output is correct
73 Correct 609 ms 39156 KB Output is correct
74 Correct 1363 ms 38500 KB Output is correct
75 Correct 1301 ms 44212 KB Output is correct
76 Correct 1198 ms 47544 KB Output is correct