Submission #162885

#TimeUsernameProblemLanguageResultExecution timeMemory
162885abacabaBigger segments (IZhO19_segments)C++14
0 / 100
2 ms380 KiB
#include <iostream> #include <string> #include <unordered_map> #include <cstring> #include <chrono> #include <vector> #include <map> #include <random> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <bitset> #include <cstdlib> #include <deque> #include <cassert> #include <stack> using namespace std; #define int long long const int inf = 2e9; const int mod = 1e9 + 7; const int N = 5e5 + 15; int n, m, a[N], p[N], maxp[N], dp[N]; main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; ++i) { cin >> a[i]; p[i] = p[i-1] + a[i]; maxp[i] = max(maxp[i-1], p[i]); } for(int i = 1; i <= n; ++i) { int l = 1, r = i - 1; dp[i] = 1; while(l <= r) { int mid = l + r >> 1; if(2 * p[mid] - maxp[mid - 1] <= p[i] && dp[mid]) dp[i] = max(dp[i], dp[mid] + 1), l = mid + 1; else r = mid - 1; } } cout << dp[n] << endl; return 0; }

Compilation message (stderr)

segments.cpp:29:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
segments.cpp: In function 'int main()':
segments.cpp:41:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             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...