#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define ll long long
vector<int> p1(vector<int>a,vector<int>r,vector<int>u,vector<int>v) {
int n=a.size(), m=u.size();
vector<int> s(n);
vector<int> f(n);
vector<int> ans(n);
forn(i,m) if (u[i]==v[i]) s[u[i]]=1;
forn(i,m) if (u[i]!=v[i]) f[u[i]]=1;
int now=0;
for (int i=n-1; i>=0; --i) {
if (s[i]) {
if (now) {
if (!a[i]) {
if (!r[i]) now=0;
} else {
if (f[i]) now=1;
else now = r[i];
}
} else {
if (a[i]) {
if (r[i]) now=1;
} else {
if (f[i]) now=0;
else now = r[i];
}
}
}
ans[i]=now;
}
return ans;
}
const int N=5555;
vector<int> adj[N];
int vis[N];
int ok[N];
int dfs(int u, int s) {
if (vis[u] && u==s) return 1;
if (vis[u]) return 0;
vis[u]=1;
int z=0;
for(auto&v:adj[u]) z|=dfs(v,s);
return z;
}
int dfs2(int u) {
if (ok[u]) return 1;
if (vis[u]) return 0;
vis[u]=1;
int z=0;
for(auto&v:adj[u]) z|=dfs2(v);
return z;
}
vector<int> p3(vector<int>a,vector<int>r,vector<int>u,vector<int>v) {
int n=a.size(), m=u.size();
vector<int> ans(n);
forn(i,m) adj[u[i]].pb(v[i]);
forn(i,n) if (r[i]) {
forn(j,n) vis[j]=0;
int q=dfs(i,i);
ok[i]=q;
}
forn(i,n) {
forn(j,n) vis[j]=0;
int q=dfs2(i);
ans[i]=q;
}
return ans;
}
int no[N];
int x=1;
int d[N], up[N];
void dfs3(int u, int l=-1) {
//cout<<"! "<<u<<' '<<vis[u]<<' '<<x<<'\n';
if (vis[u]) return;
vis[u]=1;
up[u]=N;
for(auto&v:adj[u]) {
if (!vis[v]) d[v]=d[u]+1;
else up[u]=min(up[u],d[v]);
dfs3(v,no[u]?d[u]:l);
up[u]=min(up[u],up[v]);
}
ok[u]=up[u]>l;
}
vector<int> p4(vector<int>a,vector<int>r,vector<int>u,vector<int>v) {
int n=a.size(), m=u.size();
vector<int> ans(n);
forn(i,m) adj[u[i]].pb(v[i]);
forn(i,n) no[i]=r[i];
forn(i,n) {
forn(j,n) vis[j]=0;
x=1;
dfs3(i);
//cout<<"- "<<ok[i]<<'\n';
}
forn(i,n) ans[i]=!ok[i];
return ans;
}
vector<int> who_wins(vector<int>a,vector<int>r,vector<int>u,vector<int>v) {
int n=a.size(), m=u.size();
int z=1;
forn(i,m) z&=(u[i]==v[i]) || (v[i]==(u[i]+1));
if (z) {
return p1(a,r,u,v);
}
z=1;
forn(i,n) z&=a[i];
if (z) return p3(a,r,u,v);
forn(i,n) z|=a[i];
if (!z) return p4(a,r,u,v);
exit(1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
740 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
740 KB |
Output is correct |
7 |
Correct |
3 ms |
740 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
1736 KB |
Output is correct |
2 |
Correct |
119 ms |
1696 KB |
Output is correct |
3 |
Correct |
133 ms |
1636 KB |
Output is correct |
4 |
Correct |
689 ms |
1628 KB |
Output is correct |
5 |
Correct |
607 ms |
1584 KB |
Output is correct |
6 |
Correct |
451 ms |
1516 KB |
Output is correct |
7 |
Correct |
209 ms |
1484 KB |
Output is correct |
8 |
Correct |
189 ms |
1492 KB |
Output is correct |
9 |
Correct |
172 ms |
1444 KB |
Output is correct |
10 |
Correct |
244 ms |
1440 KB |
Output is correct |
11 |
Correct |
215 ms |
1400 KB |
Output is correct |
12 |
Correct |
19 ms |
1380 KB |
Output is correct |
13 |
Correct |
747 ms |
1632 KB |
Output is correct |
14 |
Correct |
807 ms |
1620 KB |
Output is correct |
15 |
Correct |
782 ms |
1628 KB |
Output is correct |
16 |
Correct |
802 ms |
1620 KB |
Output is correct |
17 |
Correct |
824 ms |
1620 KB |
Output is correct |
18 |
Correct |
262 ms |
1312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
809 ms |
1508 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 |
Runtime error |
4 ms |
980 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
740 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
740 KB |
Output is correct |
7 |
Correct |
3 ms |
740 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Runtime error |
1 ms |
340 KB |
Execution failed because the return code was nonzero |
13 |
Halted |
0 ms |
0 KB |
- |