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;
vector<vector<int> > graf(2*lim);
vector<vector<int> > graph(MAX_N);
vector<vector<int> > rev(2*lim);
int convert(int i,int j,int k)
{
int br=i+j*MAX_N+k*lim;
return br;
}
int convert_back(int tr)
{
int j=0,k=0;
while(tr>=lim)
tr-=lim,k++;
while(tr>=MAX_N)
tr-=MAX_N,j++;
//printf("%i %i %i\n",tr,j,k);
return tr;
}
vector<int> value(2*lim);
vector<int> nxt(2*lim);
vector<int> todo;
vector<int> futuretodo;
void update(int tr)
{
//printf("Updeatujem ");
//convert_back(tr);
if(value[tr]!=0)
return;
if(tr>=lim)
{
bool neodredjen=true;
for(auto p:rev[tr])
{
if(value[p]==0)
{
neodredjen=false;
continue;
}
if(value[p]==-1)
{
value[tr]=-1;
futuretodo.pb(tr);
return;
}
}
if(neodredjen)
{
value[tr]=1;
futuretodo.pb(tr);
}
}
else
{
bool neodredjen=true;
for(auto p:rev[tr])
{
if(value[p]==0)
{
neodredjen=false;
continue;
}
if(value[p]==1)
{
nxt[tr]=convert_back(p);
value[tr]=1;
futuretodo.pb(tr);
return;
}
}
if(neodredjen)
{
value[tr]=-1;
futuretodo.pb(tr);
}
}
}
int pos=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)
{
todo.pb(convert(i,j,0));
todo.pb(convert(i,j,1));
value[convert(i,j,0)]=1;
value[convert(i,j,1)]=1;
continue;
}
//printf("%i %i %i->%i %i %i: %i->%i\n",i,j,0,i,j,1,convert(i,j,0),convert(i,j,1));
graf[convert(i,j,1)].pb(convert(i,j,0));
rev[convert(i,j,0)].pb(convert(i,j,1));
for(auto p:graph[i])
{
//printf("%i %i %i->%i %i %i: %i->%i\n",i,j,0,p,j,1,convert(i,j,0),convert(p,j,1));
graf[convert(p,j,1)].pb(convert(i,j,0));
rev[convert(i,j,0)].pb(convert(p,j,1));
}
for(auto p:graph[j])
{
//printf("%i %i %i->%i %i %i: %i->%i\n",i,j,1,i,p,0,convert(i,j,1),convert(i,p,0));
graf[convert(i,p,0)].pb(convert(i,j,1));
rev[convert(i,j,1)].pb(convert(i,p,0));
}
}
}
while(todo.size())
{
futuretodo.clear();
/*for(auto p:todo)
printf("%i ",p);
printf("\n");*/
for(auto p:todo)
for(auto d:graf[p])
update(d);
todo=futuretodo;
}
bool t=true;
for(int i=1;i<N;i++)
if(value[convert(0,i,0)]!=1)
t=false;
if(t)
return 0;
return -1;
}
int nextMove(int R)
{
return pos=nxt[convert(pos,R,0)];
}
# | 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... |