Submission #952175

#TimeUsernameProblemLanguageResultExecution timeMemory
952175nguyennhBigger segments (IZhO19_segments)C++14
0 / 100
1 ms464 KiB
#include<bits/stdc++.h> #define el '\n' using namespace std ; mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); const int64_t inf = 1e18; int32_t main (){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n + 5); for ( int i = 1 ; i <= n ; i++ ) cin >> a[i]; vector<int64_t> pref(n + 5); for ( int i = 1 ; i <= n ; i++ ) pref[i] = pref[i - 1] + a[i]; vector<vector<int64_t>> dp(n + 5 , vector<int64_t>(n + 5)); for ( int i = 1 ; i <= n ; i++ ){ for ( int j = i ; j >= 1 ; j-- ){ int l = 0 , r = j , pos = -1; while (l <= r){ int mid = l + r >> 1; if (pref[j - 1] - pref[mid - 1] <= pref[i] - pref[j - 1]){ pos = mid; r = mid - 1; } else l = mid + 1; } assert(pos != -1); for ( int k = pos ; k <= j - 1 ; k++ ) dp[i][j] = max(dp[i][j] , dp[j - 1][k] + 1); } } int64_t ans = 0; for ( int i = 1 ; i <= n ; i++ ){ ans = max(ans , dp[n][i]); } cout << ans; }

Compilation message (stderr)

segments.cpp: In function 'int32_t main()':
segments.cpp:23:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |         int mid = 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...