이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n; cin >> n;
vector<int> a(n + 1), pref(n + 1);
for (int i = 1; i<= n; i++){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
vector<vector<int>> dp(n + 1, vector<int> (n + 1, -1));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) dp[i][0] = 1e18;
for (int j = 1; j <= n; j++){
for (int i = j; i <= n; i++){
int ini = j, fin = i;
while(ini < fin){
int m = (ini + fin) / 2;
if (dp[m][j - 1] == -1 || (dp[m][j - 1] >= 0 && pref[i] >= dp[m][j - 1] + pref[m])){
ini = m + 1;
}else{
fin = m;
}
}
ini--;
int suma = pref[i] - pref[ini];
if (suma >= dp[ini][j - 1] && dp[ini][j - 1] >= 0){
dp[i][j] = suma;
}
}
}
int ans = 1;
for (int i = 1; i <= n; i++){
if (dp[n][i] != -1) ans = max(ans, i);
}
cout << ans << endl;
}
# | 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... |