| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 32118 | gs14004 | Split the sequence (APIO14_sequence) | C++14 | 2000 ms | 4360 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, int> pi;
int n,k;
lint dp[100005], a[100005];
int trk[100005], cnt[100005];
pi trial(lint x){
for(int i=1; i<=n; i++){
dp[i] = -1e18;
for(int j=0; j<i; j++){
if(dp[i] <= dp[j] + 2 * (a[n] - a[i]) * (a[i] - a[j]) - x){
dp[i] = dp[j] + 2 * (a[i] - a[j]) * (a[n] - a[i]) - x;
trk[i] = j;
cnt[i] = cnt[j] + 1;
}
}
}
return pi(dp[n], cnt[n]);
}
int main(){
int t;
scanf("%d %d",&n,&k);
for (int i=0; i<n; i++) {
scanf("%d",&t);
a[i+1] = a[i] + t;
}
lint s = -1, e = 1e13;
while(s != e){
lint m = s + (e - s + 1)/2;
if(trial(m).second >= k+1) s = m;
else e = m-1;
}
cout << (trial(s).first + s * (k+1)) / 2 << endl;
int p = n;
vector<int> v;
for(int j=k; j; j--){
v.push_back(trk[p]);
p = trk[p];
}
reverse(v.begin(), v.end());
for(auto &i : v) printf("%d ", i);
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
