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;
constexpr size_t N = 300;
int32_t f[(N << 1) - 1][N], a[N], u[N], v[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
size_t n, last_playground = -1;
cin >> n;
int32_t sum_a = 0;
for (size_t i = 0; i < n; ++i)
{
cin >> a[i];
if (a[i] >= 0)
u[i] = last_playground, sum_a += a[i];
else
last_playground = i;
}
last_playground = n;
for (size_t i = n - 1; i < n; --i)
{
if (a[i] >= 0)
v[i] = last_playground;
else
last_playground = i;
}
for (size_t i = 0; i < (N << 1) - 1; ++i)
fill(f[i], f[i] + N, INT32_MIN);
for (size_t i = 0; i < n; ++i)
f[i][i] = 0;
int32_t ans = 0;
for (int32_t i = 0; i < (n << 1) - 1; ++i)
for (int32_t j = 0; j < n; ++j)
{
for (int32_t k = 0; k < n; ++k)
if (i >= abs(j - k))
f[i][j] = max(f[i][j], f[i - abs(j - k)][k]);
if (a[j] > 0)
{
if (i <= (j << 1) && u[j] != -1 && i + j - u[j] < (n << 1) - 1)
{
f[i + j - u[j]][u[j]] = max(f[i + j - u[j]][u[j]], f[i][j] + 1);
}
if (i <= (j << 1) && v[j] != n && i + v[j] - j < (n << 1) - 1)
{
f[i + v[j] - j][v[j]] = max(f[i + v[j] - j][v[j]], f[i][j] + 1);
}
ans = max(ans, f[i][j] + (i <= (j << 1)));
}
}
cout << sum_a - ans << '\n';
}
Compilation message (stderr)
tortoise.cpp: In function 'int main()':
tortoise.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int32_t i = 0; i < (n << 1) - 1; ++i)
| ~~^~~~~~~~~~~~~~
tortoise.cpp:42:31: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int32_t j = 0; j < n; ++j)
| ~~^~~
tortoise.cpp:44:35: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int32_t k = 0; k < n; ++k)
| ~~^~~
tortoise.cpp:49:65: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
49 | if (i <= (j << 1) && u[j] != -1 && i + j - u[j] < (n << 1) - 1)
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~
tortoise.cpp:53:43: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
53 | if (i <= (j << 1) && v[j] != n && i + v[j] - j < (n << 1) - 1)
| ~~~~~^~~~
tortoise.cpp:53:64: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
53 | if (i <= (j << 1) && v[j] != n && i + v[j] - j < (n << 1) - 1)
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~
# | 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... |