# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073032 | 2024-08-24T08:47:58 Z | KasymK | Split the sequence (APIO14_sequence) | C++17 | 1 ms | 348 KB |
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 1005; const int K = 205; int v[N], par[N], id[N][K]; ll dp[N][K]; int main(){ freopen("file.txt", "r", stdin); int n, k; scanf("%d%d", &n, &k); for(int i = 1; i <= n; ++i){ int x; scanf("%d", &x); v[i] = x; } for(int i = 1; i <= n; ++i) par[i] = par[i-1]+v[i]; for(int i = 1; i <= n; ++i) for(int j = 0; j < i; ++j) for(int x = 1; x <= min(k, i); ++x) if(umax(dp[i][x], dp[j][x-1]+(par[i]-par[j])*(par[n]-par[i]))) id[i][x] = j; ll answer = 0; for(int i = 1; i <= n; ++i) umax(answer, dp[i][k]); int d = 0, x = k; for(int i = 1; i <= n; ++i) if(dp[i][k] == answer){ d = i; break; } vector<int> A; while(x){ A.pb(d); d = id[d][x]; --x; } printf("%lld\n", answer); for(int i = k-1; i >= 0; --i) printf("%d ", A[i]); puts(""); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 344 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 348 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 348 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 348 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 344 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 348 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |