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;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> ti;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ld,ld> pld;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front
#define ff first
#define ss second
#define MOD (ll)(1000000007)
#define INF (ll) (1e18)
#define all(v) (v).begin(),(v).end()
const int nx[8] = {0, 0, 1, -1,1,1,-1,-1}, ny[8] = {1, -1, 0, 0,1,-1,1,-1}; //East, West, South, North+
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
////////////******SOLUTION******\\\\\\\\\\\
const int MAX_NN = 500;
int n;
vi adj[MAX_NN];
int state[MAX_NN];
int pos;
int dp[MAX_NN][MAX_NN][2];
int f(int i, int j, int turn)
{
if(dp[i][j][turn] != -1)
return dp[i][j][turn];
if(turn == 0)
{
if(i == j)
return dp[i][j][turn] = -2;
for(auto e: adj[i])
{
if(e == j)
continue;
if(f(e,j,1-turn) == -2)
return dp[i][j][turn] = e;
}
return dp[i][j][turn] = -2;
}
else
{
if(i == j)
return dp[i][j][turn] = j;
for(auto e: adj[j])
{
if(e == i)
return dp[i][j][turn] = 0;
if(f(i,e,1-turn) == -2)
return dp[i][j][turn] = e;
}
if(f(i,j,1-turn) == -2)
return dp[i][j][turn] = j;
return dp[i][j][turn] = -2;
}
}
int nextMove(int r)
{
return dp[r][pos][1];
}
int start(int N, bool A[MAX_NN][MAX_NN])
{
n = N;
memset(dp,-1,sizeof(dp));
for(int i = 0; i <n-1; i++)
{
for(int j = i + 1; j <n; j ++)
{
if(A[i][j])
{
adj[i].pb(j);
adj[j].pb(i);
}
}
}
memset(state,0,sizeof(state));
for(int j = 0; j <n; j ++)
{
bool flag = true;
for(int i =0; i <n; i ++)
{
flag = flag & (f(i,j,0) == -2);
}
state[j] = flag;
}
int u = -1;
for(int j = 0; j <n; j ++)
{
u = state[j]? j: u;
}
return u;
}
/* 6 3 2
2 5 1 5 1 3 6 3 6 4
3 2 3 4
2 1 6
3 1 6 4
*/
/*
6 3 3
1 3
2 3
3 4
6 4
4 5
2 1 3
2 6 3
2 3 2
*/
Compilation message (stderr)
coprobber.cpp:25:1: warning: multi-line comment [-Wcomment]
25 | ////////////******SOLUTION******\\\\\\\\\\\
| ^
# | 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... |