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>
#define lp(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
const int MAXN = 5010 ;
const int MAXM = 20010 ;
using namespace std ;
int n , m ;
int a[MAXN] , r[MAXN] , v[MAXM] , u[MAXM] ;
int dp[MAXN][MAXN] ;
vector<int> adj[MAXN] ;
// -------------------
bool goodSelfLoop(int i)
{
for(int j : adj[i])
if( j == i && r[i] && ( a[i] || adj[i].size() == 1 ) )
return true ;
return false ;
}
bool badSelfLoop(int i)
{
for(int j : adj[i])
if( j == i && !r[i] && ( !a[i] || adj[i].size() == 1) )
return true ;
return false ;
}
vector<int> parcial()
{
vector<int> ans(n) ;
for(int i = 0 ; i < n ; i++ )
{
int x = i ;
bool isBad = false ;
while(true)
{
if( badSelfLoop(x) )
{ isBad = true ; break ; }
else if ( goodSelfLoop(x) )
{ isBad = false ; break ; }
for(int j : adj[x])
if( j != x )
{ x = j ; break ; }
}
for(int j = i ; j <= x ; j++ )
ans[i] = !isBad ;
i = x ;
}
return ans ;
}
vector<int> who_wins(vector<int> A , vector<int> R, vector<int> U , vector<int> V )
{
n = A.size() ;
m = U.size() ;
lp(i,0,n) a[i] = A[i] , r[i] = R[i] ;
lp(i,0,m) adj[U[i]].pb(V[i]) ;
return parcial() ;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |