Submission #1076325

# Submission time Handle Problem Language Result Execution time Memory
1076325 2024-08-26T13:01:03 Z speedcode Split the sequence (APIO14_sequence) C++17
0 / 100
2000 ms 131072 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;

ll dp1[100001][201];
int dp2[100001][201];
int n;
int Dat[100001];
ll f(int m, int k){
    if(k+1 > n + 1 - m) return 0;
    if(k == 0) return 0;
    if(dp1[m][k] != -1) return dp1[m][k];
    ll res = 0;
    for(int i = m+1; i <= n; i++){
        ll r = (Dat[i-1] - Dat[m-1])*(Dat[n] - Dat[i-1]) + f(i, k-1);
        if(r > res){
            res = r;
            dp2[m][k] = i;
        }
    }
    dp1[m][k] = res;
    return res;
}

void solve(){
    int k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= k; j++){
            dp1[i][j] = -1;
            dp2[i][j] = -1;
        }
    }
    Dat[0] = 0;
    for(int i = 1; i <= n; i++){
        cin >> Dat[i];
        Dat[i] += Dat[i-1];
    }

    cout << f(1, k) << '\n';
    int key = 1;
    while(true){
        key = dp2[key][k];
        if(key == -1) break;
        cout << key-1 << ' ';
        k--;
    }
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB contestant found the optimal answer: 108 == 108
2 Correct 1 ms 348 KB contestant found the optimal answer: 999 == 999
3 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 1 ms 344 KB contestant found the optimal answer: 302460000 == 302460000
3 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 1 ms 860 KB contestant found the optimal answer: 311760000 == 311760000
3 Incorrect 1 ms 860 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2652 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 5 ms 2652 KB contestant found the optimal answer: 140412195 == 140412195
3 Incorrect 347 ms 2840 KB declared answer doesn't correspond to the split scheme: declared = 391498272124, real = 49482974465404
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 489 ms 24088 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 406 ms 23896 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Execution timed out 2078 ms 24156 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 51 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -