이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vll;
const int mod = 1000000007;
int main(){
SPEED;
int N; cin >> N;
vll arr(N+2), pref(N+2), dp(N+2);
vi best(N+2);
for( int i = 1; i <= N; i++ ){
cin >> arr[i];
pref[i] = pref[i-1] + arr[i];
}
for( int i = 1; i <= N; i++ ){
best[i] = max( best[i], best[i-1] );
dp[i] = 1 + dp[best[i]];
lli currSum = 2 * pref[i] - pref[best[i]];
int next = lower_bound(pref.begin() + 1, pref.begin() + N + 1, currSum ) - pref.begin();
best[next] = max( best[next], i );
}
cout << dp[N] << endl;
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... |