#include <bits/stdc++.h>
#include "train.h"
using namespace std;
const int MAX_N = 5005;
const int MAX_M = 20005;
int N, M;
bool ok;
vector <int> graph[MAX_N], rgraph[MAX_N];
int A[MAX_N], R[MAX_N], good[MAX_N];
bool visited[MAX_N];
bool self[MAX_N], nxt[MAX_N];
vector <int> ans;
bool dfs(int u, int x) {
visited[u] = true;
for (auto v : graph[u]) {
if (v == x) return true;
if (visited[v] == false and dfs(v, x) == true) return true;
}
return false;
}
bool dfs3(int u, int x) {
visited[u] = true;
for (auto v : graph[u]) {
if (v == x) return true;
if (visited[v] == false and R[v] == 0 and dfs3(v, x) == true) return true;
}
return false;
}
bool dfs2(int u) {
visited[u] = true;
if (R[u] == 1) return true;
for (auto v : graph[u]) {
if (visited[v] == false and dfs2(v) == true) return true;
}
return false;
}
void dfs4(int v) {
visited[v] = true;
ans[v] = 0;
for (auto u : rgraph[v]) {
if (visited[u] == false) dfs4(u);
}
}
vector <int> who_wins(vector <int> a, vector <int> r, vector <int> u, vector <int> v) {
N = a.size(), M = u.size();
bool all_1 = true, sub1 = true;
for (int i = 0; i < N; i++) {
A[i] = a[i], R[i] = r[i];
if (A[i] == 0) all_1 = false;
}
for (int i = 0; i < M; i++) {
if (u[i] != v[i] and u[i] != v[i] - 1) sub1 = false;
if (u[i] == v[i]) self[u[i]] = true;
else if (u[i] + 1 == v[i]) nxt[u[i]] = true;
graph[u[i]].push_back(v[i]);
}
ans = vector <int> (N, 0);
if (sub1 == true) {
ok = R[N - 1];
for (int i = N - 1; i >= 0; i--) {
if (self[i] == true) {
if (R[i] == 1 and A[i] == 1) ok = true;
else if (R[i] == 0 and A[i] == 0) ok = false;
}
ans[i] = ok;
if (i > 0 and nxt[i - 1] == false) ok = R[i - 1];
}
}
else if (all_1 == true) {
for (int s = 0; s < N; s++) {
if (R[s] == 0) continue;
for (int i = 0; i < N; i++) visited[i] = false;
if (dfs(s, s) == false) R[s] = 0;
}
for (int s = 0; s < N; s++) {
for (int i = 0; i < N; i++) visited[i] = false;
ans[s] = dfs2(s);
}
}
else {
ans = vector <int> (N, 1);
for (int s = 0; s < N; s++) {
if (R[s] == 1) continue;
for (int i = 0; i < N; i++) visited[i] = false;
if (dfs3(s, s) == false) continue;
for (int i = 0; i < N; i++) visited[i] = false;
dfs4(s);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
980 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
852 KB |
Output is correct |
7 |
Correct |
3 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
1376 KB |
Output is correct |
2 |
Correct |
112 ms |
1340 KB |
Output is correct |
3 |
Correct |
124 ms |
1364 KB |
Output is correct |
4 |
Correct |
88 ms |
1252 KB |
Output is correct |
5 |
Correct |
103 ms |
1308 KB |
Output is correct |
6 |
Correct |
431 ms |
1236 KB |
Output is correct |
7 |
Correct |
137 ms |
1212 KB |
Output is correct |
8 |
Correct |
83 ms |
1204 KB |
Output is correct |
9 |
Correct |
174 ms |
1200 KB |
Output is correct |
10 |
Correct |
69 ms |
1172 KB |
Output is correct |
11 |
Correct |
109 ms |
1104 KB |
Output is correct |
12 |
Correct |
18 ms |
1140 KB |
Output is correct |
13 |
Correct |
351 ms |
1340 KB |
Output is correct |
14 |
Correct |
683 ms |
1344 KB |
Output is correct |
15 |
Correct |
499 ms |
1364 KB |
Output is correct |
16 |
Correct |
18 ms |
1236 KB |
Output is correct |
17 |
Correct |
60 ms |
1268 KB |
Output is correct |
18 |
Correct |
250 ms |
1176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1108 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
319 ms |
1348 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
980 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
852 KB |
Output is correct |
7 |
Correct |
3 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
852 KB |
Output is correct |
12 |
Incorrect |
1 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
13 |
Halted |
0 ms |
0 KB |
- |