# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
575931 | SHZhang | Game (APIO22_game) | C++17 | 1293 ms | 3960 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <queue>
#include <vector>
using namespace std;
vector<int> graph[30005];
vector<int> rgraph[30005];
int n, k;
int first_go[30005], last_come[30005];
int finish = 0;
queue<int> que;
bool inque[30005];
void push_queue(int x)
{
if (!inque[x]) {
que.push(x); inque[x] = true;
}
}
int pop_queue()
{
int res = que.front(); que.pop();
inque[res] = false;
return res;
}
void init(int N, int K) {
n = N; k = K;
for (int i = 0; i < n; i++) {
first_go[i] = n;
last_come[i] = -1;
}
for (int i = 0; i + 1 < k; i++) {
graph[i].push_back(i+1);
rgraph[i+1].push_back(i);
}
for (int i = 0; i < k; i++) {
first_go[i] = last_come[i] = i;
}
}
int add_teleporter(int u, int v) {
if (v <= u && u < k) return 1;
graph[u].push_back(v);
rgraph[v].push_back(u);
push_queue(u);
push_queue(v);
while (!que.empty()) {
int node = pop_queue();
int old_first_go = first_go[node];
for (int i = 0; i < graph[node].size(); i++) {
int nxt = graph[node][i];
first_go[node] = min(first_go[node], first_go[nxt]);
}
if (old_first_go != first_go[node]) {
for (int i = 0; i < rgraph[node].size(); i++) {
int nxt = rgraph[node][i];
push_queue(nxt);
}
}
int old_last_come = last_come[node];
for (int i = 0; i < rgraph[node].size(); i++) {
int nxt = rgraph[node][i];
last_come[node] = max(last_come[node], last_come[nxt]);
}
if (old_last_come != last_come[node]) {
for (int i = 0; i < graph[node].size(); i++) {
int nxt = graph[node][i];
push_queue(nxt);
}
}
if (node >= k && first_go[node] <= last_come[node]) finish = 1;
}
return finish;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |