Submission #308803

#TimeUsernameProblemLanguageResultExecution timeMemory
308803nikatamlianiBigger segments (IZhO19_segments)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> #define f first #define s second #define ll long long using namespace std; const int N = 5e5 + 10; pair < int, ll > dp[N]; ll sum[N], n; int main() { cin >> n; for(int i = 1; i <= n; ++i) cin >> sum[i], sum[i] += sum[i - 1]; for(int i = 1; i <= n; ++i) { int l = 1, r = i, ans = 1; while(r >= l) { int m = l + r >> 1; if(sum[i] - sum[m - 1] >= dp[m - 1].s || dp[m - 1].f < dp[i - 1].f) { l = m + 1; ans = m; } else { r = m - 1; } } dp[i].f = dp[ans - 1].f + 1; dp[i].s = sum[i] - sum[ans - 1]; // for(int j = 0; j < i; ++j) { // if(sum[i] - sum[j] >= dp[j].s) { // if(dp[i].f == dp[j].f + 1) { // dp[i].s = min(dp[i].s, sum[i] - sum[j]); // } // if(dp[i].f < dp[j].f + 1) { // dp[i].s = sum[i] - sum[j]; // dp[i].f = dp[j].f + 1; // } // } // } } cout << dp[n].f << '\n'; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:15:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |             int m = l + r >> 1;
      |                     ~~^~~
#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...