Submission #337430

# Submission time Handle Problem Language Result Execution time Memory
337430 2020-12-20T18:28:38 Z ogibogi2004 Split the sequence (APIO14_sequence) C++14
78 / 100
1617 ms 100276 KB
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
const ld INF=2e9;
const ll MAXN=1e5+6;
const ll MAXK=222;
ll dp[MAXN][2],a[MAXN];
int last[MAXN][MAXK];
struct line
{
	ld a,b;
	ll pos;
	ld llersect(line const& other)
	{
		if(a==other.a)return -INF;
		return (ld)(other.b-b)/(a-other.a);
	}
	ld gety(ld x)
	{
		return a*x+b;
	}
};
struct ConvexHull
{
	deque<pair<line,double> >dq;
	void add(line l)
	{
		while(!dq.empty()&&l.llersect(dq.back().first)<=dq.back().second)
		{
			dq.pop_back();
		}
		if(dq.empty())dq.push_back({l,-INF});
		else dq.push_back({l,l.llersect(dq.back().first)});
	}
	pair<ld,int> query(ld x)
	{
		while(dq.size()>1&&dq[1].second<=x)dq.pop_front();
		//cout<<dq.front().first.a<<" "<<dq.front().first.b<<endl;
		return {dq.front().first.gety(x),dq.front().first.pos};
	}
}ch[2];
ll n,k;
ll pref[MAXN];
int main()
{
	cin>>n>>k;
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
		pref[i]=pref[i-1]+a[i];
	}
	/*for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=k+1;j++)dp[i][j]=-INF;
	}*/
	//for(ll i=1;i<=k+1;i++)ch[i].add({0,-INF});
	ch[0].add({0,0,0});
	for(int j=1;j<=k+1;j++)
	{
		ch[j%2].dq.clear();
		ch[j%2].add({0,-INF,-1});
		for(int i=1;i<=n;i++)
		{
			tie(dp[i][j%2],last[i][j])=ch[1-j%2].query(pref[i]);
			//cout<<i<<" "<<j<<" "<<last[i][j]<<endl;
		}
		for(int i=1;i<=n;i++)
		{
			ch[j%2].add({(ld)pref[i],(ld)dp[i][j%2]-pref[i]*pref[i],i});
		}
	}
	cout<<dp[n][1-k%2]<<endl;
	vector<ll>v;
	ll n1=n;
	for(ll i=k;i>=1;i--)
	{
		v.push_back(last[n1][i+1]);
		//cout<<n1<<" "<<i+1<<endl;
		n1=last[n1][i+1];
	}
	/*
	for(ll i=k;i>=1;i--)
	{
		for(ll l1=l-1;l1>=0;l1--)
		{
			if(dp[l1][i]+(pref[l]-pref[l1])*pref[l1]==dp[l][i+1])
			{
				v.push_back(l1);
				l=l1;
				break;
			}
		}
	}*/
	sort(v.begin(),v.end());
	for(auto xd:v)
	{
		if(xd>=1&&xd<=n)cout<<xd<<" ";
	}
	cout<<endl;
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB contestant found the optimal answer: 108 == 108
2 Correct 0 ms 364 KB contestant found the optimal answer: 999 == 999
3 Incorrect 0 ms 364 KB Integer 2 violates the range [1, 1]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 1 ms 364 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 1 ms 364 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 1 ms 364 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 1 ms 364 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 1 ms 364 KB contestant found the optimal answer: 933702 == 933702
7 Correct 1 ms 364 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 1 ms 364 KB contestant found the optimal answer: 687136 == 687136
9 Correct 1 ms 364 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 1 ms 364 KB contestant found the optimal answer: 29000419931 == 29000419931
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 1 ms 492 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 3 ms 492 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 1 ms 492 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 3 ms 492 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Incorrect 3 ms 492 KB Integer 200 violates the range [1, 199]
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1260 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 1 ms 1388 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 13 ms 1388 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 1 ms 1388 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 14 ms 1388 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 12 ms 1260 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 14 ms 1388 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 13 ms 1388 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 4 ms 1388 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 6 ms 1388 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9836 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 9 ms 10220 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Correct 124 ms 10348 KB contestant found the optimal answer: 4973126687469639 == 4973126687469639
4 Correct 11 ms 10348 KB contestant found the optimal answer: 3748491676694116 == 3748491676694116
5 Correct 86 ms 10220 KB contestant found the optimal answer: 1085432199 == 1085432199
6 Correct 94 ms 9964 KB contestant found the optimal answer: 514790755404 == 514790755404
7 Correct 106 ms 10348 KB contestant found the optimal answer: 1256105310476641 == 1256105310476641
8 Correct 82 ms 10436 KB contestant found the optimal answer: 3099592898816 == 3099592898816
9 Correct 94 ms 10220 KB contestant found the optimal answer: 1241131419367412 == 1241131419367412
10 Correct 116 ms 10220 KB contestant found the optimal answer: 1243084101967798 == 1243084101967798
# Verdict Execution time Memory Grader output
1 Correct 86 ms 97772 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Correct 87 ms 98540 KB contestant found the optimal answer: 19874432173 == 19874432173
3 Correct 1508 ms 100204 KB contestant found the optimal answer: 497313449256899208 == 497313449256899208
4 Correct 95 ms 100204 KB contestant found the optimal answer: 374850090734572421 == 374850090734572421
5 Correct 1617 ms 98412 KB contestant found the optimal answer: 36183271951 == 36183271951
6 Correct 1030 ms 97260 KB contestant found the optimal answer: 51629847150471 == 51629847150471
7 Correct 1132 ms 100276 KB contestant found the optimal answer: 124074747024496432 == 124074747024496432
8 Correct 935 ms 100076 KB contestant found the optimal answer: 309959349080800 == 309959349080800
9 Correct 1043 ms 99272 KB contestant found the optimal answer: 124113525649823701 == 124113525649823701
10 Correct 1309 ms 99256 KB contestant found the optimal answer: 124309619349406845 == 124309619349406845