Submission #117139

# Submission time Handle Problem Language Result Execution time Memory
117139 2019-06-15T00:59:22 Z Lawliet Shortcut (IOI16_shortcut) C++14
0 / 100
2 ms 384 KB
#include <bits/stdc++.h>
#include "shortcut.h"

//colocar grader

#define MAX 1000010
#define INF 1000000000000000000LL

using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;

int N, C;

lli L[MAX];
lli D[MAX];
lli sL[MAX];
lli mxLeft[MAX];
lli mxRight[MAX];
lli prefixDist[MAX];
lli suffixDist[MAX];

lli dist(int i, int j) { return sL[j - 1] - sL[i - 1]; }

void init()
{
	for(int g = 1 ; g <= N - 1 ; g++)
		sL[g] = sL[g - 1] + L[g];

	for(int g = 1 ; g <= N ; g++)
		mxLeft[g] = max(mxLeft[g - 1] , D[g - 1]) + L[g - 1];

	for(int g = N ; g >= 1 ; g--)
		mxRight[g] = max(mxRight[g + 1] , D[g + 1]) + L[g];

	for(int i = 1 ; i <= N ; i++)
		suffixDist[i] = max(suffixDist[i + 1] , mxRight[i] + D[i]);

	for(int i = 1 ; i <= N ; i++)
		prefixDist[i] = max(prefixDist[i - 1] , mxLeft[i] + D[i]);
}

long long int find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
	N = n;

	for(int g = 0 ; g < n - 1 ; g++) L[g + 1] = l[g];
	for(int g = 0 ; g < n ; g++) D[g + 1] = d[g];

	init();

	lli ans = INF;

	for(int i = 1 ; i <= n ; i++)
	{
		for(int j = i + 1 ; j <= n ; j++)
		{
			lli ansIJ = -1;

			ansIJ = max(prefixDist[i] , suffixDist[j]);

			//if(i != 2 || j != 3) continue;

			//printf("i = %d  j = %d      %lld  %lld\n",i,j,prefixDist[i],suffixDist[j]);

			lli cnt = dist(i , j);

			for(int myPoint = i ; myPoint <= j ; myPoint++)
			{
				lli distance;

				if(myPoint != i)
				{
					distance = dist(i , myPoint);
					distance = min(distance , c + cnt - distance);

					ansIJ = max(ansIJ , mxLeft[i] + distance + D[myPoint] );

					//printf("my = %d      %lld %lld %lld\n",myPoint,mxLeft[i], distance,D[myPoint]);
				}

				for(int g = i + 1 ; g < j ; g++)
				{
					if(g == myPoint) continue;

					distance = dist(g , myPoint);
					if(distance < 0) distance = -distance;
					distance = min(distance , c + cnt - distance);

					ansIJ = max(ansIJ , D[g] + distance + D[myPoint] );
				}

				if(myPoint != j)
				{
					distance = dist(myPoint , j);
					distance = min(distance , c + cnt - distance);

					ansIJ = max(ansIJ , D[myPoint] + distance + mxRight[j] );

					//printf("- my = %d      %lld %lld %lld\n",myPoint,mxRight[j], distance,D[myPoint]);
				}
			}

			//ansIJ = max(ansIJ , mxLeft[i - 1] + L[i - 1] + D[i]);
			//ansIJ = max(ansIJ , mxRight[j + 1] + L[j] + D[j]);
			ansIJ = max(ansIJ , min(cnt , (long long int) c) + mxRight[j] + mxLeft[i]);

			//printf("------------------------------ i = %d  j = %d     %d\n",i,j,ansIJ);

			ans = min(ans , ansIJ);
		}
	}

	return ans;
}

/*int main()
{
	scanf("%d %d",&N,&C);

	vector<int> dd(N), ll(N - 1);

	for(int g = 0 ; g < N - 1 ; g++)
		scanf("%d",&ll[g]);

	for(int g = 0 ; g < N ; g++)
		scanf("%d",&dd[g]);

	printf("%lld\n",find_shortcut(N , ll , dd , C));
}*/
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -