| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1137532 | viwlesxq | 선물상자 (IOI15_boxes) | C++20 | 0 ms | 328 KiB |
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
long long delivery(int n, int k, int l, int p[]) {
auto dist = [&](int x, int y) {
if (x > y) swap(x, y);
return min(y - x, x + (l - y) % l);
};
long long res = 0;
deque<int> q;
for (int i = 0; i < n; ++i) {
q.push_back(p[i]);
}
int pos = 0;
while (!q.empty()) {
int f, c = k;
if (dist(pos, q.front()) < dist(pos, q.back())) f = 1;
else f = 0;
while (!q.empty() && c--) {
if (f) {
if (q.front() - pos < pos + (l - q.back()) % l) {
res += q.front() - pos;
pos = q.front();
q.pop_front();
} else {
res += pos + (l - q.back()) % l;
pos = q.back();
q.pop_back();
f = 0, c = k - 1;
}
} else {
if (((pos ? pos : l) - q.back()) % l < (l - pos) % l + q.front()) {
res += ((pos ? pos : l) - q.back()) % l;
pos = q.back();
q.pop_back();
} else {
res += (l - pos) % l + q.front();
pos = q.front();
q.pop_front();
f = 1, c = k - 1;
}
}
}
res += dist(pos, 0);
pos = 0;
}
return res;
}
| # | 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... | ||||
