이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>
using namespace std;
typedef long long ll;
const int maxn=5e5+5;
ll a[maxn];
ll pref[maxn];
array < ll, 3 > dp[maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i=0; i<n; i++){
cin >> a[i];
pref[i+1]=pref[i]+a[i];
}
dp[0]={a[0], -1, 1};
int pos=-1;
for(int i=1; i<n; i++){
while(pos<i-1 && pref[i+1]-pref[pos+2]>=dp[pos+1][0]){
pos++;
}
// cout << pref[i+1]-pref[pos+1] << endl;
if(pref[i+1]-pref[pos+1]>=dp[pos][0]){
dp[i]={pref[i+1]-pref[pos+1], pos, dp[i-1][2]+1};
pos=i;
continue;
}
dp[i]={pref[i+1]-pref[pos+1], pos, dp[i-1][2]};
}
cout << dp[n-1][2] << '\n';
return 0;
}
# | 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... |