이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define int long long
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
//const int E = 5e5+777;
//const long long inf = 1e18+777;
//const int N = 3e3+777;
//const int MOD = 1e9+7;
int getfast(vector<int> v){
int n = sz(v);
int pref[n+2]{}, a[n+2]{};
vector<vector<int>> dp(n+3, vector<int>(n+3, 0LL));
for(int i = 0; i < n; ++i) a[i+1] = v[i];
for(int i = 1; i <= n; ++i) pref[i] = pref[i-1] + a[i];
auto get = [&](int l, int r){
if(l == -1 || r == -1) return -(int)1e9;
return pref[r] - pref[l-1];
};
for(int i = 1; i <= n; ++i) dp[1][i] = 1;
for(int l = 2; l <= n; ++l){
for(int r = l; r <= n; ++r){
int mx = -1;
for(int k = 1; k < l; ++k){
if(get(k, l-1) <= get(l, r)){
mx = max(mx, dp[k][l-1]);
}
}
if(mx == -1){
dp[l][r] = mx;
}else{
dp[l][r] = mx + 1;
}
}
}
// for(int i = 1; i <= n; ++i){
// for(int j = i; j <= n; ++j){
// cerr << "{" << i << "," << j << "}: " << dp[i][j] << '\n';
// }
// }
int res = 0;
for(int i = 1; i <= n; ++i){
res = max(res, dp[i][n]);
}
return res;
}
signed main(){
ios_base::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
int n; cin >> n;
vector<int> a(n);
for(auto &i : a) cin >> i;
cout << getfast(a);
}
# | 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... |