제출 #497445

#제출 시각아이디문제언어결과실행 시간메모리
497445NalrimetBigger segments (IZhO19_segments)C++17
13 / 100
8 ms12104 KiB
#include <bits/stdc++.h> #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, old; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; v[0].pb(0); //8 //7 2 3 5 1 4 6 10 for(int i = 1; i <= n; ++i){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; dp[i] = max(1ll, dp[i - 1]); mn[i] = inf; old = dp[i - 1]; for(auto to : v[old]){ if(pref[i] >= mn[to]){ dp[i] = old + 1; mn[i] = min(mn[i], 2 * pref[i] - pref[to]); } } if(dp[i] == old){ for(auto to : v[old - 1]){ if(pref[i] >= mn[to]){ 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; }
#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...