This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n + 1), b, c;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] > 0) {
b.push_back(i);
} else if (a[i] == -1) {
c.push_back(i);
}
}
vector dp(2 * n + 1, vector(n + 1, vector<int>(n + 1, -1)));
dp[0][1][0] = 0;
for (int i = 0; i < 2 * n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 0; k < int(b.size()); k++) {
if (dp[i][j][k] == -1)
continue;
for (int p = k; p < int(b.size()); p++) {
int x = b[k];
for (int y : c) {
if ((i + abs(x - j) + 1) / 2 <= x) {
dp[min(2 * n, i + abs(x - j) + abs(x - y))][y][p + 1] = dp[i][j][k] + 1;
}
}
}
}
}
}
int ans = 0;
for (int i = 0; i <= 2 * n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 0; k < int(b.size()); k++) {
ans = max(ans, dp[i][j][k]);
}
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |