#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define bend(a) (a).begin(), (a).end()
#define isz(a) ((int)(a).size())
struct edge_t{
int from, to;
};
const int N = 5e3 + 5, M = 2e4 + 5;
int n, m;
int a[N]; // true = A, false = B
bool b[N]; // is charging station
edge_t edge[M];
vector <int> adj[N], radj[N];
bool has_self_loop[N];
namespace subtask1{
bool check(){
For(i, 0, m){
if (not (edge[i].from == edge[i].to or edge[i].from + 1 == edge[i].to)){
return false;
}
}
return true;
}
vector <int> solve(){
vector <bool> has_next_edge(n, false);
For(i, 0, m){
if (edge[i].from + 1 == edge[i].to){
has_next_edge[edge[i].from] = true;
}
}
vector <int> ans(n);
ans[n - 1] = b[n - 1];
FordE(u, n - 2, 0){
if (not has_self_loop[u]){
ans[u] = ans[u + 1];
continue;
}
if (a[u] and (b[u] or (has_next_edge[u] and ans[u + 1]))){
ans[u] = a[u];
}
else if (not a[u] and (not b[u] or (has_next_edge[u] and not ans[u + 1]))){
ans[u] = a[u];
}
else{
ans[u] = a[u] ^ 1;
}
}
return ans;
}
}
namespace subtask3{
bool check(){
return *max_element(a, a + n) == 1;
}
vector <int> vis;
vector <int> order;
vector <int> cpn;
vector <vector <int>> scc;
void dfs_topo(int u){
vis[u] = true;
for (auto i: adj[u]){
int v = edge[i].to;
if (not vis[v]){
dfs_topo(v);
}
}
order.emplace_back(u);
}
void dfs_cpn(int u){
vis[u] = true;
cpn.emplace_back(u);
for (auto i: radj[u]){
int v = edge[i].from;
if (not vis[v]){
dfs_cpn(v);
}
}
}
vector <int> solve(){
vis.assign(n, false);
For(u, 0, n){
if (not vis[u]){
dfs_topo(u);
}
}
reverse(bend(order));
vis.assign(n, false);
for (auto u: order){
if (vis[u]){
continue;
}
cpn.clear();
dfs_cpn(u);
scc.emplace_back(cpn);
}
reverse(bend(scc));
vector <int> ans(n, false);
for (auto &cpn: scc){
bool has_b = false, ok = false;
for (auto u: cpn){
if (b[u]){
has_b = true;
}
for (auto i: adj[u]){
int v = edge[i].to;
if (ans[v]){
ok = true;
}
}
}
if (has_b){
if (isz(cpn) >= 2){
ok = true;
}
for (auto u: cpn){
if (has_self_loop[u]){
ok = true;
}
}
}
for (auto u: cpn){
ans[u] = ok;
}
}
return ans;
}
}
vector <int> who_wins(vector <int> _a, vector <int> _r, vector <int> _u, vector <int> _v){
n = isz(_a); m = isz(_u);
For(u, 0, n){
a[u] = _a[u];
b[u] = _r[u];
}
For(i, 0, m){
int u = _u[i], v = _v[i];
edge[i] = edge_t{u, v};
adj[u].emplace_back(i);
radj[v].emplace_back(i);
}
For(i, 0, m){
auto [u, v] = edge[i];
if (u == v){
has_self_loop[u] = true;
}
}
if (subtask1::check()){
return subtask1::solve();
}
if (subtask3::check()){
return subtask3::solve();
}
return vector <int>(n);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1028 KB |
Output is correct |
3 |
Correct |
3 ms |
1140 KB |
Output is correct |
4 |
Correct |
3 ms |
1020 KB |
Output is correct |
5 |
Correct |
3 ms |
1108 KB |
Output is correct |
6 |
Correct |
3 ms |
1132 KB |
Output is correct |
7 |
Correct |
3 ms |
1108 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
3 ms |
1108 KB |
Output is correct |
10 |
Correct |
3 ms |
980 KB |
Output is correct |
11 |
Correct |
3 ms |
1040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
468 KB |
3rd lines differ - on the 8th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1992 KB |
Output is correct |
2 |
Correct |
5 ms |
1876 KB |
Output is correct |
3 |
Correct |
5 ms |
1876 KB |
Output is correct |
4 |
Correct |
6 ms |
1748 KB |
Output is correct |
5 |
Correct |
6 ms |
1764 KB |
Output is correct |
6 |
Correct |
6 ms |
1620 KB |
Output is correct |
7 |
Correct |
6 ms |
1620 KB |
Output is correct |
8 |
Correct |
7 ms |
1632 KB |
Output is correct |
9 |
Correct |
7 ms |
1620 KB |
Output is correct |
10 |
Correct |
6 ms |
1492 KB |
Output is correct |
11 |
Correct |
6 ms |
1492 KB |
Output is correct |
12 |
Correct |
6 ms |
1732 KB |
Output is correct |
13 |
Correct |
6 ms |
1764 KB |
Output is correct |
14 |
Correct |
7 ms |
1824 KB |
Output is correct |
15 |
Correct |
6 ms |
1876 KB |
Output is correct |
16 |
Correct |
6 ms |
1748 KB |
Output is correct |
17 |
Correct |
6 ms |
1748 KB |
Output is correct |
18 |
Correct |
7 ms |
1648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1236 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 |
6 ms |
1748 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1028 KB |
Output is correct |
3 |
Correct |
3 ms |
1140 KB |
Output is correct |
4 |
Correct |
3 ms |
1020 KB |
Output is correct |
5 |
Correct |
3 ms |
1108 KB |
Output is correct |
6 |
Correct |
3 ms |
1132 KB |
Output is correct |
7 |
Correct |
3 ms |
1108 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
3 ms |
1108 KB |
Output is correct |
10 |
Correct |
3 ms |
980 KB |
Output is correct |
11 |
Correct |
3 ms |
1040 KB |
Output is correct |
12 |
Incorrect |
0 ms |
468 KB |
3rd lines differ - on the 8th token, expected: '0', found: '1' |
13 |
Halted |
0 ms |
0 KB |
- |