Submission #712993

# Submission time Handle Problem Language Result Execution time Memory
712993 2023-03-20T18:28:57 Z piOOE Game (APIO22_game) C++17
60 / 100
4000 ms 41772 KB
#include "game.h"
#include <bits/stdc++.h>

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

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

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

bool found = false;

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

        save[i][0] = inf, save[i][1] = -inf;
    }
}

void dfs2(int v, int x);

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

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

    fromMe[v] = x;

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

    if ((toMe[v] >> B) == (fromMe[v] >> B)) {
        if (save[v][1] >= 0) {
            int s = save[v][1];
            save[v][1] = -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] >> B) != (toMe[v] >> B) && (toMe[v] >> B) >= (x >> B)) {
        save[v][1] = std::max(save[v][1], x);
        return;
    }

    toMe[v] = x;

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

    if ((toMe[v] >> B) == (fromMe[v] >> B)) {
        if (save[v][0] <= k) {
            int s = save[v][0];
            save[v][0] = 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 8 ms 14416 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 7 ms 14396 KB Output is correct
12 Correct 8 ms 14288 KB Output is correct
13 Correct 8 ms 14392 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 7 ms 14416 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 8 ms 14416 KB Output is correct
19 Correct 7 ms 14304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 7 ms 14396 KB Output is correct
12 Correct 8 ms 14288 KB Output is correct
13 Correct 8 ms 14392 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 7 ms 14416 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 8 ms 14416 KB Output is correct
19 Correct 7 ms 14304 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 7 ms 14416 KB Output is correct
22 Correct 8 ms 14416 KB Output is correct
23 Correct 8 ms 14436 KB Output is correct
24 Correct 8 ms 14416 KB Output is correct
25 Correct 10 ms 14416 KB Output is correct
26 Correct 11 ms 14436 KB Output is correct
27 Correct 8 ms 14500 KB Output is correct
28 Correct 8 ms 14672 KB Output is correct
29 Correct 9 ms 14652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 7 ms 14396 KB Output is correct
12 Correct 8 ms 14288 KB Output is correct
13 Correct 8 ms 14392 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 7 ms 14416 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 8 ms 14416 KB Output is correct
19 Correct 7 ms 14304 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 7 ms 14416 KB Output is correct
22 Correct 8 ms 14416 KB Output is correct
23 Correct 8 ms 14436 KB Output is correct
24 Correct 8 ms 14416 KB Output is correct
25 Correct 10 ms 14416 KB Output is correct
26 Correct 11 ms 14436 KB Output is correct
27 Correct 8 ms 14500 KB Output is correct
28 Correct 8 ms 14672 KB Output is correct
29 Correct 9 ms 14652 KB Output is correct
30 Correct 28 ms 15928 KB Output is correct
31 Correct 12 ms 15272 KB Output is correct
32 Correct 24 ms 16856 KB Output is correct
33 Correct 34 ms 16732 KB Output is correct
34 Correct 71 ms 18484 KB Output is correct
35 Correct 56 ms 17324 KB Output is correct
36 Correct 37 ms 16680 KB Output is correct
37 Correct 38 ms 16700 KB Output is correct
38 Correct 31 ms 16492 KB Output is correct
39 Correct 35 ms 16528 KB Output is correct
40 Correct 112 ms 17796 KB Output is correct
41 Correct 46 ms 16976 KB Output is correct
42 Correct 41 ms 16796 KB Output is correct
43 Correct 48 ms 17308 KB Output is correct
44 Correct 78 ms 17588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 7 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 7 ms 14396 KB Output is correct
12 Correct 8 ms 14288 KB Output is correct
13 Correct 8 ms 14392 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 7 ms 14416 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 8 ms 14416 KB Output is correct
19 Correct 7 ms 14304 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 7 ms 14416 KB Output is correct
22 Correct 8 ms 14416 KB Output is correct
23 Correct 8 ms 14436 KB Output is correct
24 Correct 8 ms 14416 KB Output is correct
25 Correct 10 ms 14416 KB Output is correct
26 Correct 11 ms 14436 KB Output is correct
27 Correct 8 ms 14500 KB Output is correct
28 Correct 8 ms 14672 KB Output is correct
29 Correct 9 ms 14652 KB Output is correct
30 Correct 28 ms 15928 KB Output is correct
31 Correct 12 ms 15272 KB Output is correct
32 Correct 24 ms 16856 KB Output is correct
33 Correct 34 ms 16732 KB Output is correct
34 Correct 71 ms 18484 KB Output is correct
35 Correct 56 ms 17324 KB Output is correct
36 Correct 37 ms 16680 KB Output is correct
37 Correct 38 ms 16700 KB Output is correct
38 Correct 31 ms 16492 KB Output is correct
39 Correct 35 ms 16528 KB Output is correct
40 Correct 112 ms 17796 KB Output is correct
41 Correct 46 ms 16976 KB Output is correct
42 Correct 41 ms 16796 KB Output is correct
43 Correct 48 ms 17308 KB Output is correct
44 Correct 78 ms 17588 KB Output is correct
45 Correct 239 ms 30364 KB Output is correct
46 Correct 14 ms 19536 KB Output is correct
47 Correct 16 ms 19364 KB Output is correct
48 Correct 324 ms 41772 KB Output is correct
49 Correct 281 ms 37916 KB Output is correct
50 Execution timed out 4014 ms 33540 KB Time limit exceeded
51 Halted 0 ms 0 KB -