#include<bits/stdc++.h>
#include"train.h"
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
int owned = accumulate(all(a),0);
int n = a.size(), m = u.size();
vector<int> resp(n);
matrix<int> g(n), rev(n);
bool flag = 1;
for(int i = 0; i < m; i++){
g[u[i]].push_back(v[i]);
rev[v[i]].push_back(u[i]);
flag&=v[i] == u[i] || v[i] == u[i]+1;
}
if(owned == n){
for(int i = 0; i < n; i++){
if(!r[i])
continue;
vector<int> reach(n), reachedby(n);
auto dfs =[&](int id, auto dfs)->void{
reach[id] = 1;
for(int i : g[id])
if(!reach[i]) dfs(i,dfs);
};
auto rdfs =[&](int id, auto dfs)->void{
reachedby[id] = 1;
for(int i : rev[id])
if(!reachedby[i]) dfs(i,dfs);
};
for(int j : g[i])
dfs(j,dfs);
for(int j : rev[i])
rdfs(j,rdfs);
if(reach[i]){
for(int j = 0; j < n; j++)
resp[j]|=reachedby[j];
}
}
} else if(owned == 0){
for(int i = 0; i < n; i++){
if(r[i])
continue;
vector<int> reach(n), reachedby(n);
auto dfs =[&](int id, auto dfs)->void{
reach[id] = 1;
for(int i : g[id])
if(!reach[i] && !r[i]) dfs(i,dfs);
};
auto rdfs =[&](int id, auto dfs)->void{
reachedby[id] = 1;
for(int i : rev[id])
if(!reachedby[i]) dfs(i,dfs);
};
for(int j : g[i])
dfs(j,dfs);
for(int j : rev[i])
rdfs(j,rdfs);
if(reach[i]){
for(int j = 0; j < n; j++)
resp[j]|=reachedby[j];
}
}
for(int& i : resp)
i^=1;
} else if(flag){
for(int i = n-1; i >= 0; i--){
int t1 = 0, t2 = 0;
for(int j : g[i]){
if(j == i)
t1 = 1;
else if(j == i+1)
t2 = 1;
}
if(a[i]){
if(t2){
resp[i] = resp[i+1];
}
if(t1 && r[i])
resp[i] = 1;
} else {
resp[i] = 1;
if(t2){
resp[i] = resp[i+1];
}
if(t1 && !r[i])
resp[i] = 0;
}
}
}
return resp;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
980 KB |
Output is correct |
2 |
Correct |
4 ms |
1052 KB |
Output is correct |
3 |
Correct |
4 ms |
1108 KB |
Output is correct |
4 |
Correct |
4 ms |
1108 KB |
Output is correct |
5 |
Correct |
4 ms |
1108 KB |
Output is correct |
6 |
Correct |
4 ms |
1108 KB |
Output is correct |
7 |
Correct |
10 ms |
1108 KB |
Output is correct |
8 |
Correct |
14 ms |
1080 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
4 ms |
980 KB |
Output is correct |
11 |
Correct |
3 ms |
1076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
1492 KB |
Output is correct |
2 |
Correct |
90 ms |
1548 KB |
Output is correct |
3 |
Correct |
130 ms |
1528 KB |
Output is correct |
4 |
Correct |
522 ms |
1456 KB |
Output is correct |
5 |
Correct |
94 ms |
1440 KB |
Output is correct |
6 |
Correct |
78 ms |
1400 KB |
Output is correct |
7 |
Correct |
536 ms |
1388 KB |
Output is correct |
8 |
Correct |
7 ms |
1364 KB |
Output is correct |
9 |
Correct |
7 ms |
1304 KB |
Output is correct |
10 |
Correct |
9 ms |
1364 KB |
Output is correct |
11 |
Correct |
7 ms |
1364 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
8 ms |
1388 KB |
Output is correct |
14 |
Correct |
7 ms |
1364 KB |
Output is correct |
15 |
Correct |
9 ms |
1396 KB |
Output is correct |
16 |
Correct |
7 ms |
1392 KB |
Output is correct |
17 |
Correct |
8 ms |
1392 KB |
Output is correct |
18 |
Correct |
301 ms |
1216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
1236 KB |
Output is correct |
2 |
Incorrect |
301 ms |
1412 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1364 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
980 KB |
Output is correct |
2 |
Correct |
4 ms |
1052 KB |
Output is correct |
3 |
Correct |
4 ms |
1108 KB |
Output is correct |
4 |
Correct |
4 ms |
1108 KB |
Output is correct |
5 |
Correct |
4 ms |
1108 KB |
Output is correct |
6 |
Correct |
4 ms |
1108 KB |
Output is correct |
7 |
Correct |
10 ms |
1108 KB |
Output is correct |
8 |
Correct |
14 ms |
1080 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
4 ms |
980 KB |
Output is correct |
11 |
Correct |
3 ms |
1076 KB |
Output is correct |
12 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
13 |
Halted |
0 ms |
0 KB |
- |