Submission #1114372

# Submission time Handle Problem Language Result Execution time Memory
1114372 2024-11-18T17:13:44 Z vjudge1 Bigger segments (IZhO19_segments) C++17
13 / 100
4 ms 2592 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));
    
    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 = 1, 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
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 3 ms 2384 KB Output is correct
17 Correct 4 ms 2384 KB Output is correct
18 Incorrect 3 ms 2592 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 3 ms 2384 KB Output is correct
17 Correct 4 ms 2384 KB Output is correct
18 Incorrect 3 ms 2592 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 3 ms 2384 KB Output is correct
17 Correct 4 ms 2384 KB Output is correct
18 Incorrect 3 ms 2592 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 3 ms 2384 KB Output is correct
17 Correct 4 ms 2384 KB Output is correct
18 Incorrect 3 ms 2592 KB Output isn't correct
19 Halted 0 ms 0 KB -