# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
497421 | Nalrimet | Bigger segments (IZhO19_segments) | C++17 | 6 ms | 12064 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimization("g", on)
#pragma GCC optimize ("inline")
#pragma GCC optimization("03")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 5 * 1e5 + 5;
const int inf = 1e9 + 7;
long long a[N], pref[N], dp[N], mn[N];
vector<int> v[N];
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
v[0].pb(0);
for(int i = 1; i <= n; ++i){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
dp[i] = dp[i - 1];
mn[i] = inf;
for(auto to : v[dp[i - 1]]){
if(pref[i] >= mn[to]){
dp[i] = dp[i - 1] + 1;
mn[i] = min(mn[i], 2 * pref[i] - pref[to]);
}
}
if(mn[i] == inf){
mn[i] = mn[i - 1] + a[i] * 2;
}
v[dp[i]].pb(i);
}
cout << dp[n];
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |