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;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=5007;
/*
int a[N],r[N];
vector<int>G[N];
vector<int>RG[N];
int ile[N];
bool is[N];
vector<int> who_wins(vector<int>a,vector<int>r,vector<int>U,vector<int>V)
{
int n=sz(a),m=sz(U);
vector<int>ans(n,1);
for(int i=0;i<m;i++)
{
G[U[i]].pb(V[i]);
RG[V[i]].pb(U[i]);
}
while(true)
{
memset(ile,0,sizeof ile);
deque<int>Q;
for(int i=0;i<n;i++) if(r[i]) Q.pb(i);
while(sz(Q)>0)
{
int v=Q[0];
Q.pop_front();
for(auto u:RG[v])
{
if(is[u]) continue;
ile[u]++;
if(a[u]==1||ile[u]==sz(G[u]))
{
is[u]=1;
Q.pb(u);
}
}
}
bool xd=0;
for(int i=0;i<n;i++) if(!is[i]) ans[i]=0;
for(int i=0;i<n;i++)
{
if(!r[i]) continue;
int c=0;
for(auto u:G[i]) if(is[u]) c++;
if(c==0||(a[i]==0&&c!=sz(G[i])))
{
r[i]=0;
xd=1;
break;
}
}
if(!xd) break;
}
return ans;
}*/
vector<int> who_wins(vector<int>a,vector<int>r,vector<int>U,vector<int>V)
{
int n=sz(a),m=sz(U);
vector<int>DP(n,0);
vector<int>p(n,0);
for(int i=0;i<m;i++)
{
if(U[i]==V[i]) p[U[i]]=1;
}
DP[n-1]=r[n-1];
for(int i=n-2;i>=0;i--)
{
DP[i]=DP[i+1];
if(p[i])
{
if(a[i]==0&&r[i]==0) DP[i]=0;
if(a[i]==1&&r[i]==1) DP[i]=1;
}
}
return DP;
}
/*
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
/* int n,m;
cin>>n>>m;
vector<int>a,r;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>r[i];
vector<int>x=who_wins({0, 1},{1, 0},{0, 0, 1, 1},{0, 1, 0, 1});
for(auto a:x) cout<<a<<" ";
return 0;
}*/
Compilation message (stderr)
train.cpp:99:4: warning: "/*" within comment [-Wcomment]
99 | /* int n,m;
|
# | 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... |