Submission #376296

#TimeUsernameProblemLanguageResultExecution timeMemory
376296HalogenBigger segments (IZhO19_segments)C++14
0 / 100
145 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int N, 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, 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 = -10234567898765432; } 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("%lld", &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("%lld\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("%lld", &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...