Submission #680277

#TimeUsernameProblemLanguageResultExecution timeMemory
680277mjhmjh1104Tortoise (CEOI21_tortoise)C++17
18 / 100
1142 ms444640 KiB
#include <cstdio> #include <vector> #include <cstring> #include <algorithm> using namespace std; int n, a[500006], dist[500006], res, dp[306][606][306][2]; vector<int> playgrounds; int f(int x, int y, int z, int w) { if (dp[x][y][z][w] + 1) return dp[x][y][z][w]; dp[x][y][z][w] = 0; if (2 * x >= y && x >= z && !w && a[x] > 0) dp[x][y][z][w] = max(dp[x][y][z][w], f(x, y, x + 1, 1)); if (w && a[x] == -1) dp[x][y][z][w] = max(dp[x][y][z][w], f(x, y, z, 0) + 1); if (y < 2 * n - 1) { if (x > 0) dp[x][y][z][w] = max(dp[x][y][z][w], f(x - 1, y + 1, z, w)); if (x < n - 1) dp[x][y][z][w] = max(dp[x][y][z][w], f(x + 1, y + 1, z, w)); } else dp[x][y][z][w] = max(dp[x][y][z][w], w); return dp[x][y][z][w]; } int main() { memset(dp, -1, sizeof dp); scanf("%d", &n); long long sum = 0; for (int i = 0; i < n; i++) { scanf("%d", a + i); sum += max(a[i], 0); dist[i] = (int)1e9; if (a[i] < 0) playgrounds.push_back(i); } { int tmp = (int)1e9; for (int i = 0; i < n; i++) { if (a[i] == -1) tmp = 0; dist[i] = min(dist[i], tmp); tmp++; } tmp = (int)1e9; for (int i = n - 1; i >= 0; i--) { if (a[i] == -1) tmp = 0; dist[i] = min(dist[i], tmp); tmp++; } } printf("%lld", sum - f(0, 0, 0, 0)); }

Compilation message (stderr)

tortoise.cpp: In function 'int main()':
tortoise.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
tortoise.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d", a + i);
      |         ~~~~~^~~~~~~~~~~~~
#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...