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;
typedef long long ll;
vector<int> adj[600600], INV[600600];
int n, k, cyc;
ll a[600600]; ///1 -> left, 2 -> right, 3 -> cycle (bit string)
void add_edge(int x, int y, int first = 1){
if (first) {adj[x].push_back(y); INV[y].push_back(x);}
if (cyc) return;
int l = 1, r = k;
ll prvx = a[x], prvy = a[y];
for (int i=0;;i+=2){
if (l>r) break;
assert(i<=40);
int m = (l+r)>>1;
if (x==m) a[x] |= 1LL<<i;
if (x==m+n) a[x] |= 2LL<<i;
if (y==m) a[x] |= 1LL<<i;
if (y==m+n) a[y] |= 2LL<<i;
if (a[x]&(2LL<<i)) a[y] |= 2LL<<i;
if (a[y]&(1LL<<i)) a[x] |= 1LL<<i;
if ((a[x]&(3LL<<i)) == (3LL<<i)) cyc = 1;
if ((a[y]&(3LL<<i)) == (3LL<<i)) cyc = 1;
if (cyc) break;
if ((a[x]&(3LL<<i)) != (a[y]&(3LL<<i))) break;
if (a[x]&(1LL<<i)) r = m-1;
else l = m+1;
}
if (prvx!=a[x]) for (auto &nx:INV[x]) add_edge(nx, x, 0);
if (prvy!=a[y]) for (auto &ny:adj[y]) add_edge(y, ny, 0);
}
void init(int N, int K) {
n = N, k = K;
for (int i=1;i<k;i++){
add_edge(i, i+n);
add_edge(i+n, i+1);
}
add_edge(k, k+n);
}
int add_teleporter(int u, int v) {
++u, ++v;
add_edge(u<=k?u+n:u, v);
return cyc;
}
# | 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... |