Submission #640413

#TimeUsernameProblemLanguageResultExecution timeMemory
640413qwerasdfzxclGame (APIO22_game)C++17
100 / 100
1748 ms96640 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...