#include <bits/stdc++.h>
using namespace std;
const int MX = 5042;
int dp[16][1 << 15];
vector<int> graph[MX];
// 5 pts 2h37
int solve(int pos, int vis, vector<int>& a, vector<int>& r) {
if (dp[pos][vis] != -1)
return dp[pos][vis];
if ((vis & (1 << pos)) && (r[pos] == 1))
return (dp[pos][vis] = 1);
if (a[pos]) {
dp[pos][vis] = 0;
for (auto& x: graph[pos]) {
int nxtMsk = vis | (1 << pos);
if (solve(x, nxtMsk, a, r) == 1)
dp[pos][vis] = 1;
}
} else {
dp[pos][vis] = 1;
for (auto& x: graph[pos]) {
int nxtMsk = vis | (1 << pos);
if (solve(x, nxtMsk, a, r) == 0)
dp[pos][vis] = 0;
}
}
return dp[pos][vis];
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n;
n = (int)a.size();
for (int i = 0; i < MX; i++)
graph[i].clear();
vector<int> ans (n);
bool isChain = true;
for (int i = 0; i < (int)u.size(); i++) {
graph[u[i]].push_back(v[i]);
if (!(u[i] == v[i] || v[i] == u[i] + 1))
isChain = false;
}
if (isChain) {
for (int i = n - 1; i >= 0; i--) {
bool hasSelf = false;
bool hasNext = false;
for (auto& x: graph[i]) {
if (x == i) {
hasSelf = true;
} else {
hasNext = true;
}
}
if (a[i] == 1) {
if (hasSelf && r[i])
ans[i] = 1;
else if (hasNext)
ans[i] = ans[i + 1];
} else {
if (hasSelf && !r[i])
ans[i] = 0;
else if (hasNext)
ans[i] = ans[i + 1];
else
ans[i] = 1;
}
}
} else if (n <= 15) {
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; i++) {
if (r[i]) {
ans[i] = solve(i, 0, a, r);
}
}
for (int i = 0; i < n; i++)
ans[i] = solve(i, 0, a, r);
}
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 |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
772 KB |
Output is correct |
8 |
Correct |
3 ms |
780 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2388 KB |
Output is correct |
2 |
Correct |
2 ms |
2388 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2388 KB |
3rd lines differ - on the 3rd token, expected: '0', found: '1' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1008 KB |
Output is correct |
2 |
Correct |
5 ms |
980 KB |
Output is correct |
3 |
Correct |
5 ms |
980 KB |
Output is correct |
4 |
Incorrect |
5 ms |
980 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
852 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
980 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
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 |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
772 KB |
Output is correct |
8 |
Correct |
3 ms |
780 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
2 ms |
2388 KB |
Output is correct |
14 |
Incorrect |
2 ms |
2388 KB |
3rd lines differ - on the 3rd token, expected: '0', found: '1' |
15 |
Halted |
0 ms |
0 KB |
- |