Submission #73201

# Submission time Handle Problem Language Result Execution time Memory
73201 2018-08-28T04:10:24 Z Kmcode Shortcut (IOI16_shortcut) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

//#include "shortcut.h"


vector<int> l;
vector<int> d;

#define MAX 1000002

long long int pref[MAX];
long long int bc[MAX];
long long int c;
int n;

long long int dp[MAX];

void init(){
	for(int i=0;i<d.size();i++){
		if(i)pref[i]=pref[i-1]+l[i-1];
		pref[i]=max(pref[i],(long long int)d[i]);
	}
	for(int i=d.size()-1;i>=0;i--){
		if(i!=d.size()-1){
			bc[i]=bc[i+1]+l[i];
		}
		bc[i]=max(bc[i],(long long int)d[i]);
	}
}

int pref_id(long long int z){
	return upper_bound(pref,pref+n,z)-pref-1;
}
int bc_id(long long int z){
	return lower_bound(bc,bc+n,z,greater<long long int>() )-bc;
}

long long int p[3002][3002];

void calc(){
	for(int i=0;i<n;i++){
		long long int len=0;
		for(int j=i;j<n;j++){
			if(i==j)p[i][j]=d[i];
			else p[i][j]=len+d[i]+d[j];
			if(j+1<n)len+=l[i];
		}
	}
	for(int len=2;len<=n;len++){
		for(int i=0;i<n;i++){
			if(i+len<=n){
				int j=i+len-1;
				p[i][j]=max(p[i][j],p[i][j-1]);
				p[i][j]=max(p[i][j],p[i+1][j]);
			}
		}
	}
}

bool ok(long long int cost){
	for(int i=0;i<n;i++){
		if(pref[i]>cost)break;
		if(p[0][i]>cost)break;
		for(int j=n-1;j>=i;j--){
			if(bc[j]>cost)continue;
			if(p[j][n-1]>cost)continue;
			if(max(i,pref_id(cost-pref[i]))>=min(j+1,bc_id(cost-pref[i]-c))-1){
				if(max(i-1,pref_id(cost-pref[i]-c))+1>=min(i+1,bc_id(cost-pref[i]))){
					return true;
				}
			}
		}
	}
	return false;
}


long long find_shortcut(int n2, std::vector<int> l2, std::vector<int> d2, int c2)
{
	n=d2.size();
	c=c2;
	l=l2;
	d=d2;
	n=d2.size();
	init();
	calc();
	long long int mint=0;
	long long int maxt=111111111111LL;
	while(mint+1LL<maxt){
		long long int mid=(mint+maxt)/2LL;
		if(ok(mid)){
			maxt=mid;
		}
		else{
			mint=mid;
		}
	}
	if(ok(mint))return mint;
    return maxt;
}





int main()
{
    int n, c;
    assert(2 == scanf("%d%d", &n, &c));
    
    std::vector<int> l(n - 1);
    std::vector<int> d(n);
    for (int i = 0; i < n - 1; i++)
        assert(1 == scanf("%d", &l[i]));
    for (int i = 0; i < n; i++)
        assert(1 == scanf("%d", &d[i]));
        
    long long t = find_shortcut(n, l, d, c);
    
    
    printf("%lld\n", t);
    
    return 0;
}

Compilation message

shortcut.cpp: In function 'void init()':
shortcut.cpp:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<d.size();i++){
              ~^~~~~~~~~
shortcut.cpp:25:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i!=d.size()-1){
      ~^~~~~~~~~~~~
/tmp/ccCaDm9x.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccMdeJmZ.o:shortcut.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status