Submission #376298

#TimeUsernameProblemLanguageResultExecution timeMemory
376298HalogenBigger segments (IZhO19_segments)C++14
0 / 100
156 ms262148 KiB
#include <bits/stdc++.h> using namespace std; int N; long long presum[500005]; int memo[505][505][505]; int dp(int x, int y, int z) { if (memo[x][y][z] != -1) return memo[x][y][z]; int ans = 0; long long preseg = presum[z - 1] - presum[y], curseg = presum[x - 1] - presum[y]; if (x >= N) { if (curseg - preseg + presum[x] - presum[x - 1] >= 0) ans = 0; else ans = -N - 10; } else if (curseg - preseg < 0) ans = dp(x + 1, y, z); else ans = max( dp(x + 1, y, z), 1 + dp(x + 1, x, z) ); // printf("%lld %lld %lld\n", ans, x, seg); return memo[x][y][z] = ans; } main() { scanf("%d", &N); memset(memo, -1, sizeof(memo)); for (int i = 1; i <= N; i++) scanf("%lld", &presum[i]); for (int i = 2; i <= N; i++) presum[i] += presum[i - 1]; printf("%d\n", dp(1, 0, 0)); }

Compilation message (stderr)

segments.cpp:29:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main() {
      |      ^
segments.cpp: In function 'int main()':
segments.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
segments.cpp:32:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |     for (int i = 1; i <= N; i++) scanf("%lld", &presum[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...