Submission #989484

# Submission time Handle Problem Language Result Execution time Memory
989484 2024-05-28T08:34:35 Z vjudge1 Split the sequence (APIO14_sequence) C++17
49 / 100
59 ms 131072 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#pragma GCC target("avx,avx2,fma")
#define ll long long
#define pb push_back
#define pu push
#define ins insert
#define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff(x,a,b,c) for (auto x=a;x<=b;x+=c)
#define fd(x,a,b,c) for (auto x=a;x>=b;x-=c)
#define int ll

using namespace std;

const int N = 1e6+5;
int n,m;
vector<int> dp_before, dp_cur;
int pref[N];
int btrk[N][205];

long long C(int i, int j)
{
	if (i>j) swap(i,j);
	return (pref[j]-pref[i-1])*(pref[j]-pref[i-1]);
}

void compute(int l, int r, int optl, int optr,int i) {
    if (l > r) return;
    int mid = (l + r)/2;
    pair<long long, int> best = {LLONG_MAX, -1};
    for (int k = optl; k <= min(mid, optr); k++) {
        best = min(best, {(k ? dp_before[k - 1] : 0) + C(k,mid), k});
    }
    btrk[mid][i] = best.second-1;
    dp_cur[mid] = best.first;
    int opt = best.second;
    compute(l, mid - 1, optl, opt,i);
    compute(mid + 1, r, opt, optr,i);
}

long long solve1() {
    dp_before.resize(n+1,0);
    dp_cur.resize(n+1,0);
    for (int i = 1; i <= n; i++) dp_before[i] = C(1,i);
    for (int i = 2; i <= m+1; i++) {
        compute(1, n , 1, n, i);
        dp_before = dp_cur;
    }
    return dp_before[n];
}

void solve()
{
	cin>>n>>m;
	vector<int> s(n+1);
	int sum = 0;
	for (int i=1;i<=n;i++) cin>>s[i],sum+=s[i];
	for (int i=1;i<=n;i++) pref[i] = pref[i-1]+s[i];;
	int ans = (sum*sum-solve1())/2;
	cout<<ans<<endl;
	int i=n,j=m+1;
	while(j>0){
		if(btrk[i][j]) cout<<btrk[i][j]<<" ";
		i = btrk[i][j]; j--;
	}
}

signed main()
{
	bruh
	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
		cout<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB contestant found the optimal answer: 108 == 108
2 Correct 1 ms 344 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 0 ms 344 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 0 ms 344 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 1 ms 344 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 0 ms 344 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 1 ms 348 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 0 ms 348 KB contestant found the optimal answer: 933702 == 933702
7 Correct 0 ms 348 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 0 ms 348 KB contestant found the optimal answer: 687136 == 687136
9 Correct 0 ms 348 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 1 ms 348 KB contestant found the optimal answer: 29000419931 == 29000419931
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 0 ms 2652 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 1 ms 2652 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 0 ms 2652 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 1 ms 2652 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Incorrect 1 ms 2708 KB Unexpected end of file - int32 expected
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 1 ms 2652 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 3 ms 2652 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 1 ms 2652 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 5 ms 2648 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 6 ms 2652 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 4 ms 2652 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 3 ms 2652 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 2 ms 2652 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 2 ms 2652 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16732 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 5 ms 16836 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Correct 51 ms 16732 KB contestant found the optimal answer: 4973126687469639 == 4973126687469639
4 Correct 6 ms 16728 KB contestant found the optimal answer: 3748491676694116 == 3748491676694116
5 Correct 57 ms 16816 KB contestant found the optimal answer: 1085432199 == 1085432199
6 Correct 51 ms 16816 KB contestant found the optimal answer: 514790755404 == 514790755404
7 Correct 47 ms 16732 KB contestant found the optimal answer: 1256105310476641 == 1256105310476641
8 Correct 37 ms 16732 KB contestant found the optimal answer: 3099592898816 == 3099592898816
9 Correct 46 ms 16732 KB contestant found the optimal answer: 1241131419367412 == 1241131419367412
10 Correct 59 ms 16728 KB contestant found the optimal answer: 1243084101967798 == 1243084101967798
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -