Submission #364058

#TimeUsernameProblemLanguageResultExecution timeMemory
364058b23vBoxes with souvenirs (IOI15_boxes)C++14
0 / 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 = K;
	ll ans = 0, lst = 0;
	for(int j = 0; j < n; ++j)
	{
		if(k == 0)
		{
			ans += 1LL * (L - p[j]);
			k = K;
			lst = 0;
		}
		ans += 1LL * (L - p[j] + lst);
		--k;
		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)
		{
			if(k == 0)
			{
				r += p[j];
				lst = 0;
				k = K;
			}
			r += 1LL * p[j] - lst;
			lst = p[j];
			--k;
		}
		if(lst != 0)
			r += 1LL * min(lst, L - lst);

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