Submission #118383

# Submission time Handle Problem Language Result Execution time Memory
118383 2019-06-18T21:27:36 Z JustasZ Boxes with souvenirs (IOI15_boxes) C++14
10 / 100
3 ms 384 KB
#include "boxes.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll delivery(int n, int k, int l, int pos[])
{
	sort(pos, pos + n);
	vector<ll>pref(n + 1, 0), suf(n + 1, 0);
	for(int i = 0; i < n; i++)
	{
		pref[i] = pos[i] + min(pos[i], l - pos[i]);
		if(i > k)
		{
			int j = i % k ? i - k : i - i % k;
			pref[i] += pref[j];
		}
	}
	for(int i = n - 1; i >= 0; i--)
	{
		suf[i] = l - pos[i] + min(pos[i], l - pos[i]);
		if(n - i > k)
		{
			int j = (n - i) % k ? i + k : i + (n - i) % k;
			suf[i] += suf[j];
		}
	}
	ll ans = 1e18;
	for(int i = 0; i < n - 1; i++)
	{
		ans = min(ans, pref[i] + suf[i + 1]);
		if(i + k < n)
		{
			ll a = pref[i] + l;
			if(i + k + 1 < n);
				a += suf[i + k + 1];
			ans = min(ans, a);
		}
	}
	ans = min(ans, pref[n - 1]);
	ans = min(ans, suf[0]);
	return ans;
}

Compilation message

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:50:21: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
    if(i + k + 1 < n);
                     ^
boxes.cpp:50:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    if(i + k + 1 < n);
    ^~
boxes.cpp:51:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     a += suf[i + k + 1];
     ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -