Submission #1116441

# Submission time Handle Problem Language Result Execution time Memory
1116441 2024-11-21T16:22:32 Z KK_1729 Bigger segments (IZhO19_segments) C++17
0 / 100
1 ms 592 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"

void printVector(vector<int> a){
    for (auto x: a) cout << x << " ";
    cout << endl;
}

void solve(){
    int n; cin >> n;
    vector<int> a(n);
    FOR(i,0,n) cin >> a[i];

    vector<pair<int, int>> dp(n); // dp[i] denotes the maximum number of segments possible and the minimum value of previous segment

    dp[0] = {1, a[0]};

    FOR(i,1,n){
        dp[i] = {dp[i-1].first, dp[i-1].second+a[i]};
        int o = a[i];
        for (int j = i-1; j >= 0; j--){
            if (o >= dp[j].second){
                if (dp[j].first+1 > dp[i].first){
                    dp[i].first = dp[j].first+1;
                    dp[i].second = o;
                }else if (dp[j].first+1 == dp[i].first){
                    dp[i].second = min(dp[i].second, o);
                }
            }
            o += a[j];
            assert(dp[i].first >= dp[i-1].first);
            assert(dp[i].second >= dp[i-1].second);
        }
    }
    
    cout << dp[n-1].first << endl;
}
int32_t main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int t = 1; // cin >> t;
    while (t--) solve();
}
# 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 Runtime error 1 ms 592 KB Execution killed with signal 6
4 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 Runtime error 1 ms 592 KB Execution killed with signal 6
4 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 Runtime error 1 ms 592 KB Execution killed with signal 6
4 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 Runtime error 1 ms 592 KB Execution killed with signal 6
4 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 Runtime error 1 ms 592 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -