Submission #987655

#TimeUsernameProblemLanguageResultExecution timeMemory
987655CSQ31Game (APIO22_game)C++17
100 / 100
2564 ms88240 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) (int)(a.size()) int n,k; const int MAXN = 3e5+1; vector<int>g[MAXN],gr[MAXN]; int L[MAXN],R[MAXN]; void init(int N, int K) { n=N; k=K; for(int i=0;i<k;i++)L[i] = R[i] = i; for(int i=k;i<n;i++){ L[i] = -1; R[i] = k; } } bool add(int u,int v){ //cout<<"edge "<<u<<" "<<v<<'\n'; //cout<<L[u]<<" "<<R[u]<<" "<<L[v]<<" "<<R[v]<<'\n'; if(L[u] >= R[v])return 1; //always cycle if(L[v] > R[u])return 0; //never forms cycle if(L[v] == L[u] && R[v] == R[u])return 0;//also never forms cycle int mu = (L[u] + R[u] + 1)/2; int mv = (L[v] + R[v] + 1)/2; //[L[u],mu-1] [mu,R[u]] if(R[v] < mu){ R[u] = mu-1; for(int x:g[u]){ if(add(u,x))return 1; } for(int x:gr[u]){ if(add(x,u))return 1; } } else if(L[u] >= mv){ L[v] = mv; for(int x:g[v]){ if(add(v,x))return 1; } for(int x:gr[v]){ if(add(x,v))return 1; } } return 0; } int add_teleporter(int u, int v) { if(u<k && v<k){ if(u>=v)return 1; return 0; } g[u].pb(v); gr[v].pb(u); return add(u,v); }
#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...