답안 #981694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
981694 2024-05-13T13:04:21 Z crafticat 게임 (APIO22_game) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> g;
vector<vector<int>> gr;
constexpr int inf = 1e9;
int absK = 0;
vector<int> toMin, fromMax;
bool pos = true;

void init(int n, int k) {
    g.resize(n + 1);
    gr.resize(n + 1);
    toMin.resize(n + 1,inf);
    fromMax.resize(n + 1,-1);
    absK = k;

    for (int i = 0; i < k; ++i) {
        toMin[i] = i;
        fromMax[i] = i;
    }
    for (int i = 0; i < k - 1; ++i) {
        g[i].push_back(i + 1);
        gr[i + 1].push_back(i);
    }
}

// U -> V
bool push(int x) {
    if (fromMax[x] >= toMin[x] && x >= absK)
        return true;
    for (auto par : gr[x]) {
        if (toMin[par] > toMin[x]) {
            toMin[par] = toMin[x];
            if (push(par)) return true;
        }
    }
    return false;
}
bool push2(int x) {
    if (fromMax[x] >= toMin[x] && x >= absK)
        return true;
    for (auto par : gr[x]) {
        if (fromMax[par] < fromMax[x]) {
            fromMax[par] = fromMax[x];
            if (push2(par)) return true;
        }
    }
    return false;
}

int add_teleporter(int u, int v) {
    if (!pos) return 1;

    if (u == v && v < absK) {
        pos = false;
        return 1;
    }

    toMin[u] = min(toMin[v],toMin[u]);
    if (push(u)) pos = false;
    fromMax[v] = max(fromMax[v], fromMax[u]);
    if (push2(v)) pos = false;
    return !pos;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 0 ms 344 KB Wrong Answer[1]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 0 ms 344 KB Wrong Answer[1]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 0 ms 344 KB Wrong Answer[1]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 0 ms 344 KB Wrong Answer[1]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 0 ms 344 KB Wrong Answer[1]
5 Halted 0 ms 0 KB -