#include <bits/stdc++.h>
#include "train.h"
using namespace std;
const int MAX_N = 5005;
const int MAX_M = 20005;
int N, M;
vector <int> graph[MAX_N];
int A[MAX_N], R[MAX_N];
bool visited[MAX_N];
bool self[MAX_N], nxt[MAX_N];
bool dfs(int u, int x, bool found) {
if (visited[u] == true) return found;
visited[u] = true;
if (R[u] == 1) found = true;
for (auto v : graph[u]) if (dfs(v, x, found) == true) return true;
return false;
}
vector <int> who_wins(vector <int> a, vector <int> r, vector <int> u, vector <int> v) {
N = a.size(), M = u.size();
for (int i = 0; i < N; i++) A[i] = a[i], R[i] = r[i];
bool sub1 = true;
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]);
}
vector <int> ans(N, 0);
if (sub1 == true) {
bool 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 {
for (int s = 0; s < N; s++) {
for (int i = 0; i < N; i++) visited[i] = false;
ans[s] = dfs(s, s, false);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
724 KB |
Output is correct |
2 |
Correct |
3 ms |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
728 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
123 ms |
1380 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
964 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
980 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
724 KB |
Output is correct |
2 |
Correct |
3 ms |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
728 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Incorrect |
0 ms |
340 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
13 |
Halted |
0 ms |
0 KB |
- |