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 <bits/stdc++.h>
#include "coprobber.h"
using namespace std;
#define pb push_back
int lim=MAX_N*MAX_N*2;
vector<vector<int> > graf(2*lim);
vector<vector<int> > graph(MAX_N);
int convert(int i,int j,int k)
{
int br=i+j*MAX_N+k*lim;
return br;
}
vector<int> winlose(2*lim);
vector<int> visited(2*lim);
int dfs(int tr)
{
visited[tr]=1;
if(winlose[tr]==1)
return 1;
int way=-1;
if(tr>=lim)
{
for(auto p:graf[tr])
{
if(visited[p])
return -1;
int val=dfs(p);
if(val==-1)
return -1;
}
return 1;
}
else
{
for(auto p:graf[tr])
{
if(visited[p])
continue;
int val=dfs(p);
if(val!=-1)
return p;
}
return -1;
}
}
int pozicija=0;
int start(int N, bool A[MAX_N][MAX_N])
{
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
if(A[i][j])
graph[i].pb(j);
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
if(i==j)
{
winlose[convert(i,j,0)]=1;
winlose[convert(i,j,1)]=1;
continue;
}
graf[convert(i,j,0)].pb(convert(i,j,1));
for(auto p:graph[i])
{
graf[convert(i,j,0)].pb(convert(p,j,1));
}
for(auto p:graph[j])
{
graf[convert(i,j,1)].pb(convert(i,p,0));
}
}
}
for(int i=0;i<N;i++)
{
fill(visited.begin(),visited.end(),0);
dfs(convert(0,i,0));
if(winlose[convert(0,i,0)]==1)
return 0;
}
return -1;
}
int convert_back(int tr)
{
tr%=lim;
tr%=MAX_N;
assert(tr>=0&&tr<=MAX_N);
return tr;
}
int nextMove(int R)
{
fill(visited.begin(),visited.end(),0);
return pozicija=convert_back(dfs(convert(pozicija,R,0)));
}
Compilation message (stderr)
coprobber.cpp: In function 'int dfs(int)':
coprobber.cpp:21:9: warning: unused variable 'way' [-Wunused-variable]
int way=-1;
^~~
# | 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... |