#include "train.h"
#define dbg(x) cerr<<#x<<": "<<x<<endl
#define here cerr<<"===================================\n"
#include <bits/stdc++.h>
#define ll int
#define sz(a) (ll)(a.size())
#define pb push_back
#define popb pop_back
#define all(a) a.begin(),a.end()
#define llinf 1000000000LL
#define fi first
#define sc second
#define pll pair<ll,ll>
#define endl '\n'
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 5005
ll n,m,it;
vector<ll> ans;
vector<ll> g[maxn];
vector<ll> cur;
ll b[maxn];
bool c[maxn];
bool vis[maxn];
bool naso = 0;
bool ok[maxn];
ll cnt = 0;
ll in[maxn],out[maxn];
void dfs(ll u,ll poc){
vis[u] = 1;
for(ll s : g[u]){
if(c[s]) continue;
if(s==poc){
naso = 1;
return;
}
if(vis[s]) continue;
dfs(s,poc);
if(naso) return;
}
}
void dfs2(ll u,ll poc){
if(c[u]) cnt++;
vis[u] = 1;
for(ll s : g[u]){
if((s==poc)&&(cnt>0)){
naso = 1;
return;
}
if(vis[s]) continue;
dfs2(s,poc);
if(naso) return;
}
if(c[u]) cnt--;
}
void dfs3(ll u){
vis[u] = 1;
for(ll s : g[u]){
if(vis[s]) continue;
dfs3(s);
ok[u]|=ok[s];
}
}
bool dfs4(ll u){
bool tu = 0;
for(ll s : g[u]) if(s==u) tu = 1;
if(!tu){
return dfs4(g[u][0]);
}
if(!b[u]&&!c[u]) return 0;
if(b[u]&&c[u]) return 1;
for(ll s : g[u]){
if(s!=u) return dfs4(s);
}
return c[u];
}
vector<int> who_wins(vector<int> a,vector<int> r,vector<int> u,vector<int> v) {
reverse(all(u)); u.pb(-1); reverse(all(u));
reverse(all(v)); v.pb(-1); reverse(all(v));
reverse(all(r)); r.pb(-1); reverse(all(r));
ll sum = 0; for(ll x : a) sum+=x;
n = sz(a);
reverse(all(a)); a.pb(-1); reverse(all(a));
for(ll i = 1;i<=n;i++) b[i] = a[i];
m = sz(u)-1;
bool sub1 = 1;
for(ll i = 1;i<=n;i++) c[i] = r[i];
for(ll i = 1;i<=m;i++){
u[i]++; v[i]++;
ll x = u[i]; ll y = v[i];
g[x].pb(y);
sub1&=((x==y)||(y-x==1));
}
if(sum==0){
for(ll i = 1;i<=n;i++){
if(c[i]) continue;
for(ll j = 1;j<=n;j++) vis[j] = 0;
naso = 0;
dfs(i,i);
if(naso) ok[i] = 1;
}
for(ll i = 1;i<=n;i++){
for(ll j = 1;j<=n;j++) vis[j] = 0;
dfs3(i);
}
for(ll i = 1;i<=n;i++) ans.pb(1^ok[i]);
return ans;
}
if(sum==n){
for(ll i = 1;i<=n;i++){
for(ll j = 1;j<=n;j++) vis[j] = 0;
naso = 0;
cnt = 0;
dfs2(i,i);
if(naso) ok[i] = 1;
}
for(ll i = 1;i<=n;i++){
for(ll j = 1;j<=n;j++) vis[j] = 0;
dfs3(i);
}
for(ll i = 1;i<=n;i++) ans.pb(ok[i]);
return ans;
}
if(sub1){
for(ll i = 1;i<=n;i++){
for(ll j = 1;j<=n;j++) vis[j] = 0;
ok[i] = dfs4(i);
}
for(ll i = 1;i<=n;i++) ans.pb(ok[i]);
return ans;
}
return {};
}
/*
4 6
0 0 0 0
0 1 0 0
0 1
0 2
0 3
1 2
1 3
2 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
852 KB |
Output is correct |
2 |
Correct |
4 ms |
852 KB |
Output is correct |
3 |
Correct |
4 ms |
884 KB |
Output is correct |
4 |
Correct |
6 ms |
852 KB |
Output is correct |
5 |
Correct |
4 ms |
892 KB |
Output is correct |
6 |
Correct |
4 ms |
800 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
8 ms |
828 KB |
Output is correct |
9 |
Correct |
5 ms |
852 KB |
Output is correct |
10 |
Correct |
5 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
WA in grader: Wrong returned array size |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
295 ms |
1400 KB |
Output is correct |
2 |
Correct |
269 ms |
1364 KB |
Output is correct |
3 |
Correct |
269 ms |
1332 KB |
Output is correct |
4 |
Correct |
1200 ms |
1272 KB |
Output is correct |
5 |
Correct |
1027 ms |
1224 KB |
Output is correct |
6 |
Correct |
889 ms |
1136 KB |
Output is correct |
7 |
Correct |
793 ms |
1108 KB |
Output is correct |
8 |
Correct |
466 ms |
1108 KB |
Output is correct |
9 |
Correct |
433 ms |
1124 KB |
Output is correct |
10 |
Correct |
596 ms |
1076 KB |
Output is correct |
11 |
Correct |
500 ms |
1060 KB |
Output is correct |
12 |
Correct |
38 ms |
980 KB |
Output is correct |
13 |
Correct |
1589 ms |
1300 KB |
Output is correct |
14 |
Correct |
1655 ms |
1296 KB |
Output is correct |
15 |
Correct |
1673 ms |
1364 KB |
Output is correct |
16 |
Correct |
1160 ms |
1408 KB |
Output is correct |
17 |
Correct |
1159 ms |
1432 KB |
Output is correct |
18 |
Correct |
475 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
653 ms |
1108 KB |
Output is correct |
2 |
Correct |
194 ms |
1036 KB |
Output is correct |
3 |
Correct |
370 ms |
1124 KB |
Output is correct |
4 |
Correct |
362 ms |
1108 KB |
Output is correct |
5 |
Correct |
509 ms |
1108 KB |
Output is correct |
6 |
Correct |
430 ms |
1108 KB |
Output is correct |
7 |
Correct |
444 ms |
1092 KB |
Output is correct |
8 |
Correct |
324 ms |
1064 KB |
Output is correct |
9 |
Correct |
24 ms |
1044 KB |
Output is correct |
10 |
Correct |
844 ms |
1296 KB |
Output is correct |
11 |
Correct |
812 ms |
1292 KB |
Output is correct |
12 |
Correct |
813 ms |
1296 KB |
Output is correct |
13 |
Correct |
642 ms |
1176 KB |
Output is correct |
14 |
Correct |
392 ms |
1076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1108 KB |
WA in grader: Wrong returned array size |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
852 KB |
Output is correct |
2 |
Correct |
4 ms |
852 KB |
Output is correct |
3 |
Correct |
4 ms |
884 KB |
Output is correct |
4 |
Correct |
6 ms |
852 KB |
Output is correct |
5 |
Correct |
4 ms |
892 KB |
Output is correct |
6 |
Correct |
4 ms |
800 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
8 ms |
828 KB |
Output is correct |
9 |
Correct |
5 ms |
852 KB |
Output is correct |
10 |
Correct |
5 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
12 |
Incorrect |
1 ms |
340 KB |
WA in grader: Wrong returned array size |
13 |
Halted |
0 ms |
0 KB |
- |