Submission #1187702

#TimeUsernameProblemLanguageResultExecution timeMemory
1187702BlockOG선물상자 (IOI15_boxes)C++20
10 / 100
0 ms328 KiB
#include <bits/stdc++.h>

// meow meow mrrrow nyaa :3
// vivid/stasis is very cool, you should play, it's free

using namespace std;

int shortest(int i, int j, int l) {
    int a = min(i, j), b = max(i, j);
    return min(b - a, l - b + a);
}

int delivery(int n, int k, int l, int positions[]) {
    map<int, int> a;
    for (int i = 0; i < n; i++) a[positions[i]]++;
    
    int pos = 0, res = 0, c = k;
    for (pair<int, int> p : a) {
        int i = p.first, v = p.second;
        
        int can_change = min(c, v);
        if (can_change) {
            v -= can_change;
            c -= can_change;
            res += shortest(pos, i, l);
            pos = i;
        }
        
        if (v) {
            int times = (v + k - 1) / k;
            v -= k * times;
            c -= v;
            
            res += 2 * times * shortest(0, i, l) - shortest(0, i, l) + shortest(0, pos, l);
            pos = i;
        }
    }
    
    res += shortest(pos, 0, l);
    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...