제출 #987656

#제출 시각아이디문제언어결과실행 시간메모리
987656CSQ31게임 (APIO22_game)C++17
2 / 100
10 ms14424 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] = 0; R[i] = k-1; } } 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...