이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 1; i <= n; i++)
{
pref[i] = pos[i - 1] * 2;
if(i - k >= 1)
pref[i] += pref[i - k];
}
for(int i = n; i >= 1; i--)
{
suf[i] = (l - pos[i - 1]) * 2;
if(i + k <= n)
suf[i] += suf[i + k];
}
ll ans = 1e18;
for(int i = 1; i < n; 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]);
ans = min(ans, suf[1]);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |