#include <vector>
#include <queue>
#include "train.h"
using namespace std;
int n, m;
vector<int> graph[5005];
int f[5005];
//int freq[5005][5005];
bool vis[5005][5005];
bool fb[5005][5005];
bool a[5005], r[5005];
bool dfs(int node, int val)
{
if (!val) return true;
if (vis[node][val]) return fb[node][val];
vis[node][val] = true;
bool cur;
if (a[node]) {
cur = false;
for (int i = 0; i < graph[node].size(); i++) {
int nxt = graph[node][i];
if (dfs(nxt, val - (int)r[node])) {
cur = true; break;
}
}
} else {
cur = true;
for (int i = 0; i < graph[node].size(); i++) {
int nxt = graph[node][i];
if (!dfs(nxt, val - (int)r[node])) {
cur = false; break;
}
}
}
return fb[node][val] = cur;
}
vector<int> who_wins(vector<int> A, vector<int> R, vector<int> u, vector<int> v) {
n = (int)A.size();
m = (int)u.size();
for (int i = 0; i < m; i++) {
graph[u[i]].push_back(v[i]);
}
for (int i = 0; i < n; i++) a[i] = A[i], r[i] = R[i];
for (int v = 1; v <= n + 1; v++) {
for (int i = 0; i < n; i++) {
dfs(i, v);
}
}
vector<int> ans(n);
for (int i = 0; i < n; i++) {
//fprintf(stderr, "%d ", f[i]);
ans[i] = (int)fb[i][n+1];
}
return ans;
}
Compilation message
train.cpp: In function 'bool dfs(int, int)':
train.cpp:25:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < graph[node].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~~
train.cpp:33:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < graph[node].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1022 ms |
49692 KB |
Output is correct |
2 |
Correct |
1075 ms |
49692 KB |
Output is correct |
3 |
Correct |
1057 ms |
49696 KB |
Output is correct |
4 |
Correct |
1012 ms |
49700 KB |
Output is correct |
5 |
Correct |
1065 ms |
49804 KB |
Output is correct |
6 |
Correct |
1016 ms |
49824 KB |
Output is correct |
7 |
Correct |
882 ms |
49660 KB |
Output is correct |
8 |
Correct |
993 ms |
49732 KB |
Output is correct |
9 |
Correct |
1016 ms |
49820 KB |
Output is correct |
10 |
Correct |
927 ms |
49688 KB |
Output is correct |
11 |
Correct |
785 ms |
49672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Incorrect |
1 ms |
460 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1417 ms |
50048 KB |
Output is correct |
2 |
Correct |
1439 ms |
50052 KB |
Output is correct |
3 |
Correct |
1500 ms |
50024 KB |
Output is correct |
4 |
Correct |
1405 ms |
49968 KB |
Output is correct |
5 |
Correct |
1970 ms |
49980 KB |
Output is correct |
6 |
Execution timed out |
2076 ms |
49988 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2005 ms |
49976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1750 ms |
50036 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1022 ms |
49692 KB |
Output is correct |
2 |
Correct |
1075 ms |
49692 KB |
Output is correct |
3 |
Correct |
1057 ms |
49696 KB |
Output is correct |
4 |
Correct |
1012 ms |
49700 KB |
Output is correct |
5 |
Correct |
1065 ms |
49804 KB |
Output is correct |
6 |
Correct |
1016 ms |
49824 KB |
Output is correct |
7 |
Correct |
882 ms |
49660 KB |
Output is correct |
8 |
Correct |
993 ms |
49732 KB |
Output is correct |
9 |
Correct |
1016 ms |
49820 KB |
Output is correct |
10 |
Correct |
927 ms |
49688 KB |
Output is correct |
11 |
Correct |
785 ms |
49672 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Incorrect |
1 ms |
460 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
19 |
Halted |
0 ms |
0 KB |
- |