#include <bits/stdc++.h>
#define int long long
#define fi first
#define pll pair<long long,long long>
#define se second
#define isz(x) (int)(x).size()
using namespace std;
const long long inf = 1e18;
const int mod = 1e9+7;
const int maxn = 1e4+5;
const int block = 500;
int dp[maxn][2],trace[maxn][maxn],ps[maxn];
void compute(int j,int l,int r,int optl,int optr){
if (l>r)return;
int mid=(l+r)>>1;
pll best={inf,-1};
for (int i=optl;i<=min(mid,optr);++i){
int x=ps[mid]-ps[i-1];
int val=dp[i-1][0]+x*x;
if (best.fi>val){
best={val,i};
trace[mid][j]=i;
}
}
dp[mid][1]=best.fi;
int opt=best.se;
compute(j,l,mid-1,optl,opt);
compute(j,mid+1,r,opt,optr);
}
void test(){
int n,k; cin>>n>>k;
for (int i=1;i<=n;++i){
cin>>ps[i];
ps[i]+=ps[i-1];
dp[i][0]=ps[i]*ps[i];
}
for (int j=2;j<=k+1;++j){
compute(j,1,n,1,n);
for (int i=1;i<=n;++i)dp[i][0]=dp[i][1];
}
int ans=(ps[n]*ps[n]-dp[n][0])/2;
cout<<ans<<"\n";
// cout<<trace[4][2]<<" ";
vector<int> path;
int i=n,j=k+1;
while (1){
path.push_back(trace[i][j]-1);
i=trace[i][j]-1; --j;
if (j==1) break;
}
for (int i=isz(path)-1;i>=0;--i)cout<<path[i]<<" ";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
test();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
1 ms |
2396 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Incorrect |
1 ms |
2396 KB |
Integer 0 violates the range [1, 1] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
1 ms |
4700 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Correct |
1 ms |
4444 KB |
contestant found the optimal answer: 122453454361 == 122453454361 |
4 |
Correct |
1 ms |
4440 KB |
contestant found the optimal answer: 93663683509 == 93663683509 |
5 |
Correct |
1 ms |
4444 KB |
contestant found the optimal answer: 1005304678 == 1005304678 |
6 |
Correct |
1 ms |
4444 KB |
contestant found the optimal answer: 933702 == 933702 |
7 |
Correct |
1 ms |
4444 KB |
contestant found the optimal answer: 25082842857 == 25082842857 |
8 |
Correct |
1 ms |
4444 KB |
contestant found the optimal answer: 687136 == 687136 |
9 |
Correct |
1 ms |
4444 KB |
contestant found the optimal answer: 27295930079 == 27295930079 |
10 |
Correct |
1 ms |
4444 KB |
contestant found the optimal answer: 29000419931 == 29000419931 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
1 ms |
12892 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Correct |
2 ms |
14940 KB |
contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 |
Correct |
1 ms |
10840 KB |
contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 |
Correct |
2 ms |
10964 KB |
contestant found the optimal answer: 1019625819 == 1019625819 |
6 |
Runtime error |
17 ms |
18012 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10332 KB |
contestant found the optimal answer: 21503404 == 21503404 |
2 |
Correct |
2 ms |
10332 KB |
contestant found the optimal answer: 140412195 == 140412195 |
3 |
Correct |
10 ms |
11868 KB |
contestant found the optimal answer: 49729674225461 == 49729674225461 |
4 |
Correct |
2 ms |
8540 KB |
contestant found the optimal answer: 37485571387523 == 37485571387523 |
5 |
Correct |
7 ms |
9820 KB |
contestant found the optimal answer: 679388326 == 679388326 |
6 |
Correct |
8 ms |
11472 KB |
contestant found the optimal answer: 4699030287 == 4699030287 |
7 |
Correct |
6 ms |
11868 KB |
contestant found the optimal answer: 12418819758185 == 12418819758185 |
8 |
Correct |
5 ms |
15708 KB |
contestant found the optimal answer: 31093317350 == 31093317350 |
9 |
Correct |
3 ms |
14428 KB |
contestant found the optimal answer: 12194625429236 == 12194625429236 |
10 |
Correct |
5 ms |
14684 KB |
contestant found the optimal answer: 12345131038664 == 12345131038664 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
54032 KB |
contestant found the optimal answer: 1818678304 == 1818678304 |
2 |
Correct |
17 ms |
53848 KB |
contestant found the optimal answer: 1326260195 == 1326260195 |
3 |
Correct |
91 ms |
67156 KB |
contestant found the optimal answer: 4973126687469639 == 4973126687469639 |
4 |
Correct |
18 ms |
52060 KB |
contestant found the optimal answer: 3748491676694116 == 3748491676694116 |
5 |
Correct |
67 ms |
57280 KB |
contestant found the optimal answer: 1085432199 == 1085432199 |
6 |
Correct |
66 ms |
58704 KB |
contestant found the optimal answer: 514790755404 == 514790755404 |
7 |
Correct |
74 ms |
61512 KB |
contestant found the optimal answer: 1256105310476641 == 1256105310476641 |
8 |
Correct |
57 ms |
59288 KB |
contestant found the optimal answer: 3099592898816 == 3099592898816 |
9 |
Correct |
67 ms |
62548 KB |
contestant found the optimal answer: 1241131419367412 == 1241131419367412 |
10 |
Correct |
101 ms |
63784 KB |
contestant found the optimal answer: 1243084101967798 == 1243084101967798 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |