# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
577101 |
2022-06-14T04:35:11 Z |
Kanon |
Toy Train (IOI17_train) |
C++14 |
|
516 ms |
80296 KB |
#include <bits/stdc++.h>
using namespace std;
vector<int> who_wins(vector<int> owned, vector<int> z, vector<int> From, vector<int> To) {
int n = owned.size();
int m = To.size();
vector<vector<int>> g(n);
vector<vector<int>> Rev(n);
for (int i = 0; i < m; i++) {
g[From[i]].push_back(To[i]);
Rev[To[i]].push_back(From[i]);
}
vector<int> ret(n, -1);
{
vector<int> was(n);
vector<int> alive(n);
function<void(int)> dfs = [&] (int v) {
was[v] = 1;
for (int i : g[v]) {
if (alive[i] && !was[i]) {
dfs(i);
}
}
};
auto winstate = [&](vector<int> keep, vector<int> nodes) {
fill(alive.begin(), alive.end(), 0);
for (int i : keep) {
alive[i] = 1;
}
vector<vector<int>> r(n);
for (int i = 0; i < n; i++) {
if (!alive[i]) {
continue;
}
dfs(i);
r[i] = was;
fill(was.begin(), was.end(), 0);
}
vector<bool> win(n);
for (int i : nodes) {
for (int j : g[i]) {
if (alive[j] && r[j][i] == 1) {
win[i] = true;
}
}
}
return win;
};
auto get_win = [&](vector<int> keep, vector<bool> &win) {
while (true) {
bool change = false;
for (int i : keep) {
if (win[i]) {
continue;
}
for (int j : g[i]) {
if (win[j]) {
win[i] = true;
change = true;
}
}
}
if (!change) {
break;
}
}
};
for (int player = 0; player < 2; player++) {
vector<int> keep;
vector<int> nodes;
for (int i = 0; i < n; i++) {
if (owned[i] != player) {
continue;
}
if (player == 1) {
keep.push_back(i);
if (z[i]) {
nodes.push_back(i);
}
} else {
if (!z[i]) {
keep.push_back(i);
nodes.push_back(i);
}
}
}
if (player == 1) {
assert(keep.empty() && nodes.empty());
}
vector<bool> win = winstate(keep, nodes);
if (player == 0) {
keep.clear();
for (int i = 0; i < n; i++) {
if (owned[i] == player) {
keep.push_back(i);
}
}
}
get_win(keep, win);
for (int i = 0; i < n; i++) {
if (win[i]) {
assert(ret[i] != (player ^ 1));
ret[i] = player;
} else {
ret[i] = player ^ 1;
}
}
}
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
26324 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
3028 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
7252 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 |
516 ms |
80296 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
26324 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |