답안 #21180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
21180 2017-04-07T22:32:23 Z sbansalcs Shortcut (IOI16_shortcut) C++14
컴파일 오류
0 ms 0 KB
#include "shortcut.h"
#include <iostream>
#include <assert.h>
const int N = 1e6+2;
typedef long long ll;
using namespace std;
ll dp1[N],dp2[N];
ll dp3[N],dp4[N];
ll sums[N];

ll comp(int i, int j)	{
	ll lx=sums[j]-sums[i];

	ll f=max(dp3[i],max(dp4[j],c+dp1[i]+dp2[j]));
	for(int x=i+1;x<j;x++)	{
		ll _x=sums[x]-sums[i];
		f=max(f,min(_x,lx-_x+c)+dp1[i]+d[x]);
		f=max(f,min(lx-_x,_x+c)+dp2[j]+d[x]);
		for(int y=x+1;y<j;y++)	{
			ll f2=sums[y]-sums[x];
			f=max(f,min(f2,lx+c-f2)+d[x]+d[y]);
		}

	}
}

long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{	
	for(int i=0;i<n;i++)	{
		if(i==0)	dp1[i]=d[i];
		else	dp1[i]=max((ll)d[i],dp1[i-1]+l[i-1]);
	}
	for(int i=n-1;i>=0;i--)	{
		if(i==n-1)	dp2[i]=d[i];
		else	dp2[i]=max((ll)d[i],dp2[i+1]+l[i]);
	}
	for(int i=0;i<n;i++)	{
		if(i==0)	dp3[i]=d[i];
		else	dp3[i]=max(dp3[i-1],d[i]+l[i-1]+dp1[i-1]);	
	}
	for(int i=n-1;i>=0;i--)	{
		if(i==n-1)	dp4[i]=d[i];
		else	dp4[i]=max(dp4[i+1],l[i]+dp2[i+1]+d[i]);
	}
	for(int i=1;i<n;i++)	{
		sums[i]=l[i-1]+sums[i-1];
	}
	// for(int i=0;i<n;i++)	{
	// 	cout<<i<<" : "<<dp3[i]<<" , "<<dp4[i]<<endl;
	// }
	ll ans=dp3[n-1];
	ll lx;
	for(int i=0;i<n;i++)	{
		for(int j=i+1;j<n;j++)	{

			lx=sums[j]-sums[i];
			if(lx<=c)	continue;

			ans=min(ans,comp(i,j));
		}
	}

    return ans;
}

Compilation message

shortcut.cpp: In function 'll comp(int, int)':
shortcut.cpp:14:29: error: 'c' was not declared in this scope
  ll f=max(dp3[i],max(dp4[j],c+dp1[i]+dp2[j]));
                             ^
shortcut.cpp:17:34: error: 'd' was not declared in this scope
   f=max(f,min(_x,lx-_x+c)+dp1[i]+d[x]);
                                  ^
shortcut.cpp:25:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^