Submission #809045

#TimeUsernameProblemLanguageResultExecution timeMemory
809045finn__Tortoise (CEOI21_tortoise)C++17
48 / 100
274 ms432584 KiB
#include <bits/stdc++.h> using namespace std; constexpr size_t N = 301; int32_t f[(N << 1) - 1][N][N], a[N], x[N], u[N], v[N]; int main() { sizeof f; ios_base::sync_with_stdio(0); cin.tie(0); int32_t n, m = 0, 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) x[m] = i, u[m] = last_playground, sum_a += a[i], ++m; else if (a[i] == -1) last_playground = i; } last_playground = n; for (size_t i = n - 1, j = m - 1; i < n; --i) { if (a[i] > 0) v[j] = last_playground, --j; else if (a[i] == -1) last_playground = i; } for (size_t i = 0; i < (N << 1) - 1; ++i) for (size_t j = 0; j < N; ++j) fill(f[i][j], f[i][j] + N, INT32_MIN); for (size_t i = 0; i < m; ++i) f[x[i]][i][0] = 0; int32_t ans = 0; for (int32_t i = 0; i < (n << 1) - 1; ++i) for (size_t j = 0; j < m; ++j) { for (size_t k = 0; k < a[x[j]] && k < n; ++k) { ans = max(ans, f[i][j][k] + (i <= (x[j] << 1))); if (i <= (x[j] << 1)) { // current shop // preceding playground. if (u[j] != -1 && i + ((x[j] - u[j]) << 1) < (n << 1) - 1) f[i + ((x[j] - u[j]) << 1)][j][k + 1] = max(f[i + ((x[j] - u[j]) << 1)][j][k + 1], f[i][j][k] + 1); // next playground. if (v[j] != n && i + ((v[j] - x[j]) << 1) < (n << 1) - 1) f[i + ((v[j] - x[j]) << 1)][j][k + 1] = max(f[i + ((v[j] - x[j]) << 1)][j][k + 1], f[i][j][k] + 1); // next shop if (j + 1 < m) { // preceding playground if (u[j] != -1 && i + (x[j] - u[j]) + (x[j + 1] - u[j]) < (n << 1) - 1) f[i + (x[j] - u[j]) + (x[j + 1] - u[j])][j + 1][0] = max(f[i + (x[j] - u[j]) + (x[j + 1] - u[j])][j + 1][0], f[i][j][k] + 1); // next playground if (v[j] != n && i + (v[j] - x[j]) + abs(x[j + 1] - v[j]) < (n << 1) - 1) f[i + (v[j] - x[j]) + abs(x[j + 1] - v[j])][j + 1][0] = max(f[i + (v[j] - x[j]) + abs(x[j + 1] - v[j])][j + 1][0], f[i][j][k] + 1); } } } if (j + 1 < m) for (size_t k = 0; k <= a[x[j]] && k <= n; ++k) if (i + x[j + 1] - x[j] < (n << 1) - 1) f[i + x[j + 1] - x[j]][j + 1][0] = max(f[i + x[j + 1] - x[j]][j + 1][0], f[i][j][k]); } cout << sum_a - ans << '\n'; }

Compilation message (stderr)

tortoise.cpp: In function 'int main()':
tortoise.cpp:10:5: warning: statement has no effect [-Wunused-value]
   10 |     sizeof f;
      |     ^~~~~~~~
tortoise.cpp:18:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   18 |     for (size_t i = 0; i < n; ++i)
      |                        ~~^~~
tortoise.cpp:28:41: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   28 |     for (size_t i = n - 1, j = m - 1; i < n; --i)
      |                                       ~~^~~
tortoise.cpp:39:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   39 |     for (size_t i = 0; i < m; ++i)
      |                        ~~^~~
tortoise.cpp:44:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   44 |         for (size_t j = 0; j < m; ++j)
      |                            ~~^~~
tortoise.cpp:46:34: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   46 |             for (size_t k = 0; k < a[x[j]] && k < n; ++k)
      |                                ~~^~~~~~~~~
tortoise.cpp:46:49: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   46 |             for (size_t k = 0; k < a[x[j]] && k < n; ++k)
      |                                               ~~^~~
tortoise.cpp:62:31: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   62 |                     if (j + 1 < m)
      |                         ~~~~~~^~~
tortoise.cpp:74:23: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   74 |             if (j + 1 < m)
      |                 ~~~~~~^~~
tortoise.cpp:75:38: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   75 |                 for (size_t k = 0; k <= a[x[j]] && k <= n; ++k)
      |                                    ~~^~~~~~~~~~
tortoise.cpp:75:54: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
   75 |                 for (size_t k = 0; k <= a[x[j]] && k <= n; ++k)
      |                                                    ~~^~~~
#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...