Submission #163017

#TimeUsernameProblemLanguageResultExecution timeMemory
163017kostia244Boxes with souvenirs (IOI15_boxes)C++14
20 / 100
2 ms380 KiB
#include "boxes.h"
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
ll n, k, l;
vi pos, dpl, dpr;
ll getl(ll x) {
	return min(2ll*x, l);
}
ll getr(ll x) {
	return min(2ll*(l-x), l);
}
long long delivery(int N, int K, int L, int P[]) {
	n=N, k = K, l = L;
	ll ans = LLONG_MAX;
	pos.resize(n+2);
	dpl.resize(n+2);
	dpr.resize(n+2);
	for(int i = 0; i < n; i++)
		pos[i+1] = P[i];
	ll p, cst;
	p=cst=0;
	for(int i = 1; i <= n; i++) {
		cst += min(abs(p-pos[i]), l-abs(p-pos[i])), p = pos[i];
		dpl[i] = cst+min(p,l-p);
		if(i%k==0) {
			cst += min(p,l-p);
			p = 0;
		}
	}
	ans = dpl[n], p = 0, cst = 0;
	for(int i = n; i; i--) {
		cst += min(abs(p-pos[i]), l-abs(p-pos[i])), p = pos[i];
		dpr[i] = cst+min(p,l-p);
		if((n-i+1)%k==0) {
			cst += min(p,l-p);
			p = 0;
		}
		ans = min(ans, dpr[i]+dpl[i-1]);
	}
    return ans;
}

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:35:14: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  for(int i = n; i; i--) {
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...