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;
int m = (l+r)>>1;
a[x] |= (ll)((x==m)?1:((x==m+n)?2:0))<<i;
a[y] |= (ll)((y==m)?1:((y==m+n)?2:0))<<i;
ll X = (a[x]&(3LL<<i))>>i, Y = (a[y]&(3LL<<i))>>i;
Y |= X&2;
X |= Y&1;
if (X==3 || Y==3) {cyc = 1; break;}
if (X!=Y) break;
a[x] |= X<<i, a[y] |= Y<<i;
if (X&1) r = m-1;
else if (X&2) l = m+1;
else break;
}
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... |