Submission #418747

#TimeUsernameProblemLanguageResultExecution timeMemory
418747nafis_shifatBoxes with souvenirs (IOI15_boxes)C++14
Compilation error
0 ms0 KiB
#include "boxes.h"
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const ll inf= 1e18;
ll delivery(int N, int K, int L, int p[]) {

	

	ll pre[2 * N + K] = {};


	deque<int> q;


	for(int i = 0; i < N; i++) {
		pre[i] = inf;
		if(i < K) pre[i] = min(L,2 * p[i]);

		while(!q.empty() && i - q.front() > K) q.pop_front();
		if(!q.empty()) {
			pre[i] = min(pre[i],pre[q.front()] + min(L,2 * p[i]));
		}

		while(!q.empty() && pre[q.back()] >= pre[i]) q.pop_back();
		q.push_back(i);
	}


	while(!q.empty()) q.pop_back();

	ll suf[2 * N + K] = {};

	for(int i = N - 1; i >= 0; i--) {
		suf[i] = inf;
		if(N - i <= K) suf[i] = min(L,2 * (L - p[i]));

		while(!q.empty() && q.front() - i > K) q.pop_front();
		if(!q.empty()) {
			suf[i] = min(suf[i],suf[q.front()] + min(L,2 *(L - p[i])));
		}

		while(!q.empty() && suf[q.back()] >= suf[i]) q.pop_back();
		q.push_back(i);





	ll res = suf[0];

	for(int i = 0; i < N; i++) res = min(res,pre[i] + suf[i + 1]);

	if(N <= K) res = min(res, 1ll * L);



	return res;
}

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:54:10: warning: declaration of 'i' shadows a previous local [-Wshadow]
   54 |  for(int i = 0; i < N; i++) res = min(res,pre[i] + suf[i + 1]);
      |          ^
boxes.cpp:36:10: note: shadowed declaration is here
   36 |  for(int i = N - 1; i >= 0; i--) {
      |          ^
boxes.cpp:61:1: error: expected '}' at end of input
   61 | }
      | ^
boxes.cpp:8:43: note: to match this '{'
    8 | ll delivery(int N, int K, int L, int p[]) {
      |                                           ^
boxes.cpp:15:13: warning: control reaches end of non-void function [-Wreturn-type]
   15 |  deque<int> q;
      |             ^