답안 #1114356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114356 2024-11-18T16:32:49 Z vjudge1 Bigger segments (IZhO19_segments) C++17
0 / 100
1 ms 504 KB
#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));
    for (int i = 0; i <= n; i++) dp[i][0] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 0; j < i; j++){
           int ini = 0, fin = i;
           while(ini < fin){
               
               int m = (ini + fin) / 2;
               if (dp[m][j] >= 0 && pref[i] >= dp[m][j] + pref[m]){
                   fin = m;
               }else ini = m + 1;
           }
           
           int suma = pref[i] - pref[ini];
           //cout << i << ' ' << j << ' ' << suma << ' ' << ini << endl;
           if (suma >= dp[ini][j] && dp[ini][j] >= 0){
               dp[i][j + 1] = suma;
           }
        }
    }
    
    
    int ans = 0;
    for (int i = 1; i <= n; i++){
        
        if (dp[n][i] != -1) ans = max(ans, i);
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -