Submission #577158

#TimeUsernameProblemLanguageResultExecution timeMemory
577158tengiz05Tortoise (CEOI21_tortoise)C++17
18 / 100
3085 ms432940 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; void chmax(i64 &a, i64 b) { if (a < b) a = b; } 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) { for (int j = 1; j <= min(a[i], n); j++) { b.push_back(i); } } else if (a[i] == -1) { c.push_back(i); } } vector<int> l(n + 1), r(n + 1); int lst = 0; for (int i = 1; i <= n; i++) { if (a[i] == -1) lst = i; l[i] = lst; } lst = n + 1; for (int i = n; i >= 1; i--) { if (a[i] == -1) lst = i; r[i] = lst; } vector dp(2 * n + 1, vector(n + 1, vector<i64>(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; chmax(dp[i][j][k + 1], dp[i][j][k]); int x = b[k]; if (l[x] != 0) { int y = l[x]; if (2 + i + abs(x - j) <= 2 * x) { chmax(dp[min(2 * n, i + abs(x - j) + 2 * abs(x - y))][x][k + 1], dp[i][j][k] + 1); } } if (r[x] != n + 1) { int y = r[x]; if (2 + i + abs(x - j) <= 2 * x) { chmax(dp[min(2 * n, i + abs(x - j) + abs(x - y))][y][k + 1], dp[i][j][k] + 1); } } } } } i64 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]); } } } i64 sum = 0; for (int i = 1; i <= n; i++) { if (a[i] > 0) { sum += a[i]; } } cout << sum - ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...