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 "coprobber.h"
#include<bits/stdc++.h>
using namespace std;
int n,st;
vector<int> adj[MAX_N];
int vis[MAX_N][MAX_N][2];
pair<int,int> dp[MAX_N][MAX_N][2];
int solve(int x,int y,int t){
if(x==y)return 1;
if(vis[x][y][t]==2)return dp[x][y][t].first;
if(vis[x][y][t]==1)return 0;
vis[x][y][t]=1;
if(t){
pair<int,int> res(solve(x,y,0),x);
for(auto v:adj[x])res=max(res,{solve(v,y,0),v});
vis[x][y][t]=2;
return (dp[x][y][t]=res).first;
}else{
int res=1;
for(auto v:adj[y])res=min(res,solve(x,v,1));
vis[x][y][t]=2;
return dp[x][y][t].first=res;
}
}
int start(int N,bool A[MAX_N][MAX_N]){
n=N;
for(int u=0;u<n;u++)for(int v=0;v<n;v++)if(A[u][v])adj[u].emplace_back(v);
for(int u=0;u<n;u++){
int res=1;
for(int v=0;v<n;v++){
res=min(res,solve(u,v,1));
}
if(res)return st=u;
}
return -1;
}
int nextMove(int R){
solve(st,R,1);
return st=dp[st][R][1].second;
}
# | 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... |