#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define size(x) (int)((x).size())
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
int n = size(a);
int SC = 2;
for (int i : r) if (i) SC++;
int chargingStation = -1;
for (int i = 0; i < n; i++) if (r[i]) {
chargingStation = i;
}
vector<vi> graph(SC*n+1);
vector<vi> ng(size(graph));
vi inc(SC*n+1, 0);
vi typ(size(graph));
typ.back() = 0;
for (int i = 0; i < SC*n; i++) {
typ[i] = a[i/SC];
}
for (int k = 0; k < size(u); k++) {
for (int i = 0; i < SC; i++) {
int to = i;
if (v[k] == chargingStation) {
to++;
}
int toNode = v[k]*SC+to;
if (to == SC) toNode = size(graph)-1;
graph[toNode].push_back(u[k]*SC+i);
ng[u[k]*SC+i].push_back(toNode);
inc[u[k]*SC+i]++;
}
}
vector<int> win(size(graph), 0);
for (int i = 0; i < size(graph); i++) win[i] = false;
queue<int> q;
q.push(size(graph)-1);
win[size(graph)-1] = true;
while (!q.empty()) {
int x = q.front();
q.pop();
for (int y : graph[x]) {
if (typ[y] == 1) {
if (!win[y]) {
q.push(y);
win[y] = true;
}
}
else {
inc[y]--;
assert(inc[y] >= 0);
if (inc[y] == 0) {
assert(!win[y]);
q.push(y);
win[y] = true;
}
}
}
}
vi fin(n);
for (int i = 0; i < n; i++) fin[i] = win[i*SC+1];
return fin;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
104 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
297 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
120 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
2772 KB |
Output is correct |
2 |
Correct |
12 ms |
2796 KB |
Output is correct |
3 |
Correct |
12 ms |
2772 KB |
Output is correct |
4 |
Correct |
11 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
2132 KB |
Output is correct |
7 |
Correct |
10 ms |
1372 KB |
Output is correct |
8 |
Correct |
6 ms |
1492 KB |
Output is correct |
9 |
Correct |
7 ms |
1492 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
6 ms |
1320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
104 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |