Submission #364057

#TimeUsernameProblemLanguageResultExecution timeMemory
364057b23vBoxes with souvenirs (IOI15_boxes)C++14
10 / 100
2 ms384 KiB
#include "boxes.h"

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <cstring>
#include <functional>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vii = vector<pair<int,int>>;
using vb = vector<bool>;
template<typename T>
using Graph = vector<vector<T>>;

ll delivery(int n, int K, int L, int p[])
{
	int k = 0;
	ll ans = 0, lst = 0;
	for(int j = 0; j < n; ++j)
	{
		ans += 1LL * (L - p[j] + lst);
		if(--k == 0)
		{
			ans += 1LL * (L - p[j]);
			k = K;
			lst = 0;
		} else
			lst = p[j];
	}
	if(lst != 0) ans += 1LL * min(lst, (L - lst));

	// TODO handle case where i go to p[0] from other side
	for(int i = 0; i < n; ++i)
	{
		k = K;
		lst = 0;
		ll r = 0;
		// dont go beyond i	
		for(int j = 0; j <= i; ++j)
		{
			r += 1LL * p[j] - lst;
			if(--k == 0)
			{
				r += p[j];
				lst = 0;
				k = K;
			} else
				lst = p[j];
		}
		if(lst != 0)
			r += lst;

		k = K;
		lst = 0;
		for(int j = i + 1; j < n; ++j)
		{
			r += 1LL * (L - p[j] + lst);
			if(--k == 0)
			{
				r += L - p[j];
				lst = 0;
				k = K;
			} else
				lst = p[j];
		}
		if(lst != 0)
			r += 1LL * min(lst, (L - lst));
		ans = min(ans, r);
	}
	return ans;
}
#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...