답안 #162546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162546 2019-11-08T18:38:44 Z MohamedAhmed04 Shortcut (IOI16_shortcut) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "shortcut.h"
#include "grader.cpp"

using namespace std ;

long long find_shortcut(int n, vector<int> dist, std::vector<int>s, int c)
{
	long long pref[n+1] , suff[n+1] , distance[n+1] , Max[n+1] , farp[n+1] , fars[n+1] ;
	pref[1] = s[0] * 1ll;
	farp[1] = s[0] * 1ll ;
	distance[1] = 0ll ;
	for(int i = 2 ; i <= n ; ++i)
	{
		farp[i] = pref[i-1] + dist[i-2]*1ll + s[i-1] ;
		pref[i] = max(pref[i-1]+dist[i-2]*1ll , s[i-1]*1ll) ;
		distance[i] = distance[i-1] + dist[i-2] * 1ll ; 
	}
	suff[n] = s[n-1] * 1ll;
	fars[n] = s[n-1] * 1ll ;
	for(int i = n-1 ; i >= 1 ; --i)
	{
		fars[i] = suff[i+1]+dist[i-1]*1ll+s[i-1]*1ll ;
		suff[i] = max(suff[i+1]+dist[i-1]*1ll , s[i-1]*1ll) ;
	}
	long long ans = 1e18 , now = 0 , val;
	for(int i = 1 ; i <= n ; ++i)
		now = max(now , max(farp[i] , fars[i])) ;
	ans = min(ans , now) ;
	for(int i = 1 ; i <= n ; ++i)
	{
		Max[i] = 0ll ;
		for(int j = i+1 ; j <= n ; ++j)
		{
			val = c * 1ll ;
			if(distance[j]-distance[i] < val)
				continue ;
			now = max(pref[i] , s[i-1] * 1ll) + max(suff[j] , s[j-1] * 1ll) + val ;
			for(int k = 1 ; k <= i ; ++k)
				now = max(now , farp[k]) ;
			for(int k = j ; k <= n ; ++k)
				now = max(now , fars[k]) ;
			for(int k = i+1 ; k < j ; ++k)
			{
				now = max(now , min(farp[k] , pref[i] + val + dist[j] - dist[k] + s[k-1] * 1ll)) ;
				//now = max(now , min(farp[k] , s[k-1] + distance[j] - distance[k] + val + max(pref[i] , s[i-1] * 1ll))) ;
				now = max(now , min(fars[k] , suff[j] + val + distance[k] - distance[i] + s[k-1] * 1ll)) ;
				//now = max(now , min(fars[k] , s[k-1] + distance[k] - distance[i] + val + max(suff[i] , s[i-1] * 1ll))) ;
				for(int x = i+1 ; x < k ; ++x)
				{
					long long a = s[x-1] + distance[k] - distance[x] + s[k-1] ;
					long long b = s[x-1] + distance[x] - distance[i] + val + distance[j] - distance[k] + s[k-1] ;
					now = max(now , max(a , b)) ;
				}
			}
			//if(j == i+1)
			//	Max[j] = s[j-1] ;
			//else
			//	Max[j] = max(Max[j-1] + dist[j-2] * 1ll , s[j-1] * 1ll) ;
			ans = min(ans , now) ;
		}
	}
    return ans ;
}

Compilation message

shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:9:52: warning: variable 'Max' set but not used [-Wunused-but-set-variable]
  long long pref[n+1] , suff[n+1] , distance[n+1] , Max[n+1] , farp[n+1] , fars[n+1] ;
                                                    ^~~
/tmp/ccXjyvv3.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccs7y2yY.o:shortcut.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status