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>
using namespace std;
int n , iswin [502][502][3] , nxt [502][502][3] , cur;
bool a [500][500];
int start(int N, bool A [500][500])
{
n = N;
for ( int i = 0 ; i < n ; i ++ )
{
for ( int j = 0 ; j < n ; j ++ ) a [i][j] = A [i][j];
iswin [i][i][0] = 1;
iswin [i][i][1] = 1;
}
while ( true )
{
int did = 0;
for ( int i = 0 ; i < n ; i ++ )
{
for ( int j = 0 ; j < n ; j ++ )
{
for ( int z = 0 ; z < 2 ; z ++ )
{
if ( iswin [i][j][z] ) continue;
int num = 0 , all = 0;
for ( int k = 0 ; k < n ; k ++ )
{
int nx = i , ny = j , can = 0 , zz = z ^ 1;
if ( zz == 0 )
{
ny = k;
if ( a [j][k] ) can = 1;
}
else
{
nx = k;
if ( a [i][k] ) can = 1;
}
if ( zz == 1 && i == k ) can = 1;
if ( can == 0 ) continue;
all ++;
if ( iswin [nx][ny][zz] )
{
nxt [i][j][z] = k;
num ++;
}
}
if ( ( z == 1 && all == num ) || ( z == 0 && num ) )
{
iswin [i][j][z] = 1;
did = 1;
}
}
}
}
if ( did == 0 ) break;
}
for ( int i = 0 ; i < n ; i ++ )
{
int num = 0;
for ( int j = 0 ; j < n ; j ++ )
{
if ( iswin [i][j][0] ) num ++;
}
if ( num == n )
{
cur = i;
return i;
}
}
return -1;
}
int nextMove(int R) {
cur = nxt [cur][R][0];
return cur;
}
/*
int main()
{
cin >> n;
for ( int i = 0 ; i < n ; i ++ )
{
for ( int j = 0 ; j < n ; j ++ ) cin >> a [i][j];
}
cout << start ( n , a ) << endl;
while ( true )
{
int x;
cin >> x;
cout << ' ' << nextMove ( x ) << endl;
}
}
*/
# | 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... |