이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#ifdef DEBUG
#define debug(x) cout << #x << ' ' << x << '\n'
#else
#define debug(x)
#endif
long long delivery(int N, int K, int L, int p[]) {
int idx = 0;
int left = N;
long long ans = 0ll;
while (left > 0) {
vector<int> cur;
for (int i = idx; i < min(idx + K, N); i++) {
cur.push_back(p[i]);
left--;
}
idx += K;
long long takeLeft = 0ll;
long long takeRight = 0ll;
{
int pos = 0;
for (auto& x : cur) {
takeLeft += (long long) (x - pos);
debug(takeLeft);
pos = x;
}
takeLeft += (long long) (min(pos, L - pos));
}
{
int pos = L;
reverse(cur.begin(), cur.end());
for (auto& x : cur) {
takeRight += (long long) (pos - x);
debug(takeRight);
pos = x;
}
takeRight += (long long) (min(pos, L - pos));
}
ans += min(takeLeft, takeRight);
debug(ans);
}
return ans;
}
/*
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, l, p[1005];
cin >> n >> k >> l;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
cout << delivery(n, k, l, p) << endl;
return 0;
}
*/
| # | 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... |