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 <bits/stdc++.h>
using namespace std;
template<class T> using vec = vector<T>;
const int N = 3e5 + 2;
int n, k, tt[N][2];
vec<int> g[N][2];
void init(int n_, int k_) {
n = n_ + 2, k = k_ + 2;
for (int i = 0; i < n; i++)
if (i < k)
tt[i][0] = tt[i][1] = i;
else
tt[i][0] = 0, tt[i][1] = k - 1;
}
bool dfs(int i, int j, int t) {
if (j < k)
return 0;
int p = tt[j][t];
tt[j][t] = (t == 0 ? max(tt[i][t], tt[j][t]) : min(tt[i][t], tt[j][t]));
if (tt[j][1] <= tt[j][0])
return 1;
if (__builtin_clz(p ^ tt[j][t ^ 1]) < __builtin_clz(tt[j][t] ^ tt[j][t ^ 1])) {
for (int v : g[j][0])
if (dfs(j, v, 0))
return 1;
for (int v : g[j][1])
if (dfs(j, v, 1))
return 1;
}
return 0;
}
int add_teleporter(int i, int j) {
i = i < k - 2 ? i + 1 : i + 2;
j = j < k - 2 ? j + 1 : j + 2;
if (i < k && j < k)
return i >= j;
g[i][0].push_back(j), g[j][1].push_back(i);
return dfs(i, j, 0) || dfs(j, i, 1);
}
# | 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... |