Submission #595875

# Submission time Handle Problem Language Result Execution time Memory
595875 2022-07-14T07:49:18 Z KoD Game (APIO22_game) C++17
2 / 100
1 ms 296 KB
#include "game.h"
#include <utility>
#include <vector>

using std::pair;
using std::vector;

int N, K;
vector<vector<int>> graph, revgraph;
vector<pair<int, int>> interval;

bool shrink_interval(int u, int a, int b) {
    auto& [l, r] = interval[u];
    const int m = l + (r - l) / 2;
    if (b < m) {
        r = m;
        shrink_interval(u, a, b);
        return true;
    }
    if (m <= a) {
        l = m;
        shrink_interval(u, a, b);
        return true;
    }
    return false;
}

void init(int n, int k) {
    N = n, K = k;
    graph.resize(n);
    revgraph.resize(n);
    interval.resize(n, pair(-1, k + 1));
    for (int i = 0; i < k; ++i) {
        shrink_interval(i, i - 1, i + 1);
    }
}

bool update_max(int u, int x) {
    if (interval[u].second <= x) return true;
    if (shrink_interval(u, x, interval[u].second)) {
        for (const int v : graph[u]) {
            if (update_max(v, x)) return true;
        }
    }
    return false;
}

bool update_min(int u, int x) {
    if (x <= interval[u].first) return true;
    if (shrink_interval(u, interval[u].first, x)) {
        for (const int v : revgraph[u]) {
            if (update_min(v, x)) return true;
        }
    }
    return false;
}

int add_teleporter(int u, int v) {
    graph[u].push_back(v);
    revgraph[u].push_back(v);
    if (update_max(v, u < K ? u : interval[u].first)) return true;
    if (update_min(u, v < K ? v : interval[v].second)) return true;
    return false;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Incorrect 1 ms 208 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Incorrect 1 ms 208 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Incorrect 1 ms 208 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Incorrect 1 ms 208 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -