이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "boxes.h"
#define ll long long
using namespace std;
const int N = int(1e7);
ll f[N];
int mid, g;
ll delivery(int n, int k, int l, int pos[])
{
mid = l >> 1;
for(int i = 0; i < n; ++i) {
if(pos[i] <= mid) {
if(i >= k) f[i] = f[i - k] + min(2 * pos[i], l);
else f[i] = min(2 * pos[i], l);
} else {
if(i >= k) f[i] = f[i - k] + min({l, 2 * (l - pos[i - k + 1]), 2 * pos[i]});
else f[i] = min({l, 2 * (l - pos[i - k + 1]), 2 * pos[i]});
}
f[i] = min(f[i], f[i - 1] + 2 * min(pos[i], l - pos[i]));
}
return f[n - 1];
}
/*int _n, _k, _l, _pos[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> _n >> _k >> _l;
for(int i = 0; i < _n; ++i) cin >> _pos[i];
cout << delivery(_n, _k, _l, _pos);
}*/
| # | 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... |