Submission #344622

#TimeUsernameProblemLanguageResultExecution timeMemory
344622NurlykhanBigger segments (IZhO19_segments)C++17
37 / 100
200 ms35820 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = (int)3000 + 10; const int mod = (int)1e9 + 7; int n; int a[N]; ll pref[N]; ll get_sum(int l, int r) { return pref[r] - pref[l - 1]; } int dp[N][N]; int main() { // freopen("in.txt", "r", stdin); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); pref[i] = pref[i - 1] + a[i]; } for (int l = 0; l <= n; l++) { for (int r = 0; r <= n; r++) { dp[l][r] = -mod; } } dp[1][1] = 1; for (int l = 1; l <= n; l++) { for (int r = l; r <= n; r++) { dp[l][r + 1] = max(dp[l][r + 1], dp[l][r]); int lo = r + 1, hi = n, ans = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (get_sum(l, r) > get_sum(r + 1, mid)) { lo = mid + 1; } else { ans = mid; hi = mid - 1; } } if (ans != -1) dp[r + 1][ans] = max(dp[r + 1][ans], dp[l][r] + 1); } } int ans = 0; for (int l = 1; l <= n; l++) ans = max(ans, dp[l][n]); cout << ans; return 0; }

Compilation message (stderr)

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