# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
646592 |
2022-09-30T09:08:23 Z |
jamezzz |
Toy Train (IOI17_train) |
C++17 |
|
1116 ms |
1760 KB |
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define maxn 5005
typedef vector<int> vi;
bool vis[maxn],cycle[maxn];
int good[maxn];
vi AL[maxn],a,r,u,v;
bool dfs(int u,int rt){
vis[u]=true;
bool have=false,all=true;
for(int v:AL[u]){
if(v==rt){
have=true;
continue;
}
if(!vis[v])dfs(v,rt);
else if(!cycle[v])all=false;
else have=true;
}
if(a[u]==1&&have)cycle[u]=true;
else if(a[u]==0&&all)cycle[u]=true;
return cycle[u];
}
bool dfs2(int u,int rt){
vis[u]=true;
bool have=false,all=true;
for(int v:AL[u]){
if(v==rt){
have=true;
continue;
}
if(!vis[v])dfs2(v,rt);
if(!cycle[v])all=false;
else have=true;
}
if(r[u]==0&&a[u]==1&&all)cycle[u]=true;
else if(r[u]==0&&a[u]==0&&have)cycle[u]=true;
return cycle[u];
}
vi who_wins(vi _a,vi _r,vi _u,vi _v){
a=_a,r=_r,u=_u,v=_v;
int n=a.size(),m=u.size();
for(int i=0;i<m;++i){
AL[u[i]].push_back(v[i]);
}
memset(good,-1,sizeof good);
for(int i=0;i<n;++i){
for(int j=0;j<n;++j)vis[j]=cycle[j]=false;
if(r[i]==1&&dfs(i,i))good[i]=1;
else if(r[i]==0&&dfs2(i,i))good[i]=0;
}
for(int i=0;i<n;++i){
bool take=false;
for(int u=0;u<n;++u){
if(good[u]!=-1)continue;
bool have=false,all=true,done=true;
for(int v:AL[u]){
if(good[v]==1)have=true;
else if(good[v]==0)all=false;
else done=false;
}
if(a[u]==1)good[u]=have,take=true;
else if(done)good[u]=all,take=true;
}
if(!take)break;
}
vi ans(n,0);
for(int i=0;i<n;++i)ans[i]=good[i];
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
282 ms |
1248 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
3rd lines differ - on the 5th token, expected: '1', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
229 ms |
1596 KB |
Output is correct |
2 |
Correct |
179 ms |
1760 KB |
Output is correct |
3 |
Correct |
187 ms |
1720 KB |
Output is correct |
4 |
Incorrect |
970 ms |
1660 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
788 ms |
1236 KB |
3rd lines differ - on the 1st token, expected: '1', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1116 ms |
1408 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
282 ms |
1248 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |