Submission #1137314

#TimeUsernameProblemLanguageResultExecution timeMemory
1137314viwlesxq선물상자 (IOI15_boxes)C++20
0 / 100
0 ms324 KiB
#include "boxes.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long i64;

i64 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 + n - y);
    };

    i64 res = 0;

    deque<int> q;
    for (int i = 0; i < n; ++i) {
        q.push_back(p[i]);
    }

    int pos = 0;

    while (!q.empty()) {
        if (dist(pos, q.front()) < dist(pos, q.back())) {
            res += dist(pos, q.front());
            pos = q.front();
            q.pop_front();
        } else {
            res += dist(pos, q.back());
            pos = q.back();
            q.pop_back();
        }
    }

    res += dist(pos, 0);

    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...