Submission #905264

# Submission time Handle Problem Language Result Execution time Memory
905264 2024-01-12T21:42:03 Z andro Split the sequence (APIO14_sequence) C++14
0 / 100
2000 ms 12376 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> pref(n + 1);
    vector<int> suf(n + 2);
    for(int i = 1; i <= n; i++) {
        pref[i] = pref[i - 1] + a[i];
    }
    for(int i = n; i > 0; i--) {
        suf[i] = suf[i + 1] + a[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(m + 1));
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= m; j++) {
            dp[i][j] = 0;
        }
    }
    vector<vector<int>> P(n + 1, vector<int>(m + 1));
    for(int i = 1; i <= n; i++) {
        dp[i][1] = (pref[i]) * (suf[i + 1]);
        P[i][1] = i;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 2; j < i; j++) {
            for(int k = 1; k < i; k++) {
                //dp[i][j] = max(dp[i][j], dp[k][j - 1] + (pref[i] - pref[k]) * suf[i + 1]);
                int s = dp[k][j - 1] + (pref[i] - pref[k]) * suf[i + 1];
                if(s > dp[i][j]) {
                    P[i][j] = k;
                    dp[i][j] = s;
                }
            }
        }
    }
    int ans = 0;
    for(int i = m + 1; i <= n; i++) {
        ans = max(ans, dp[i][m]);
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 330 ms 796 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2040 ms 1624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2039 ms 12376 KB Time limit exceeded
2 Halted 0 ms 0 KB -