Submission #374500

# Submission time Handle Problem Language Result Execution time Memory
374500 2021-03-07T10:43:37 Z Jasiekstrz Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 364 KB
#include<bits/stdc++.h>
#include "shortcut.h"
#define fi first
#define se second
using namespace std;
const int N=1e6;
int w[N+10];
int dd[N+10];
long long pref[N+10];
long long suf[N+10];
long long mx[N+10];
long long tab[N+10][2];
inline bool check(int n,int c,long long x,int a,int b)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			if(w[i]+w[j]+min({pref[j]-pref[i],abs(pref[j]-pref[a])+abs(pref[i]-pref[b])+c,
					abs(pref[i]-pref[a])+abs(pref[j]-pref[b])+c}) > x)
				return false;
		}
	}
	return true;
}

//bool ok(int n,int c,long long x)
//{
//	for(int i=1;i<=n;i++)
//	{
//		for(int j=i;j<=n;j++)
//		{
//			if(check(n,c,x,i,j))
//				return true;
//		}
//	}
//	return false;
//}

bool ok(int n,int c,long long x)
{
	int i,j;
	long long mx1,mx2;
	for(i=1;i<=n;i++)
	{
		tab[i][0]=0;
		tab[i][1]=1e15;
	}

	mx1=mx2=0;
	for(i=1;i<=n;i++)
		mx[i]=max(mx[i-1],w[i]-pref[i]);
	for(i=n;i>=1;i--)
	{
		if(mx2-pref[i]+w[i]>x)
			mx1=max(mx1,mx2+w[i]+pref[i]);
		mx2=max(mx2,w[i]+pref[i]);
		tab[i][0]=max({tab[i][0],mx1-pref[i]+c-x,mx2+mx[i]+pref[i]+c-x});
	}

	mx1=mx2=0;
	for(i=n;i>=1;i--)
		mx[i]=max(mx[i+1],w[i]-suf[i]);
	for(i=1;i<=n;i++)
	{
		if(mx2-suf[i]+w[i]>x)
			mx1=max(mx1,mx2+w[i]+suf[i]);
		mx2=max(mx2,w[i]+suf[i]);
		tab[i][1]=max({tab[i][1],mx1-suf[i]+c-x,mx2+mx[i]+suf[i]+c-x});
	}

	vector<pair<long long,int>> tmp;
	for(i=1;i<=n;i++)
		tmp.push_back({tab[i][0],i});
	sort(tmp.begin(),tmp.end());
	j=1;
	for(auto v:tmp)
	{
		while(j<n && pref[j]<v.fi)
			j++;
		//cerr<<"l: "<<v.se<<" "<<j<<" ("<<v.fi<<")\n";
		if(check(n,c,x,v.se,j))
			return true;
	}

	tmp.clear();
	for(i=1;i<=n;i++)
		tmp.push_back({tab[i][1],i});
	sort(tmp.begin(),tmp.end());
	j=n;
	for(auto v:tmp)
	{
		while(j>1 && suf[j]<v.fi)
			j--;
		//cerr<<"r: "<<v.se<<" "<<j<<" ("<<v.fi<<")\n";
		if(check(n,c,x,v.se,j))
			return true;
	}

	return false;
}

long long find_shortcut(int n,vector<int> l,vector<int> d,int c)
{
	for(int i=0;i<n;i++)
		w[i+1]=d[i];
	for(int i=0;i<n-1;i++)
		dd[i+2]=l[i];
	for(int i=1;i<=n;i++)
		pref[i]=pref[i-1]+dd[i];
	for(int i=n;i>=1;i--)
		suf[i]=suf[i+1]+dd[i+1];
	//cerr<<ok(n,c,109)<<":ok\n";
	//return 0;
	long long bg,en,mid;
	bg=0;
	en=1e16;
	while(bg<en)
	{
		mid=(bg+en)/2;
		if(ok(n,c,mid))
			en=mid;
		else
			bg=mid+1;
	}
	return bg;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 364 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 364 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 364 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 364 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 364 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 364 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 364 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 364 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -