Submission #1007109

# Submission time Handle Problem Language Result Execution time Memory
1007109 2024-06-24T11:55:25 Z The_Samurai Boxes with souvenirs (IOI15_boxes) C++17
100 / 100
588 ms 293968 KB
#include "boxes.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

ll delivery(int n, int k, int L, int p[]) {
    auto dist = [&](int i, int j) -> int {
        return min(abs(i - j), L - abs(i - j));  
    };
    sort(p, p + n);
    vector<ll> pref(n), suff(n + 1);
    for (int i = 0; i < n; i++) {
        pref[i] = p[i] + dist(0, p[i]);
        if (i >= k) pref[i] += pref[i - k];
        // for (int j = i; j < min(n, i + k); j++) {
        //     pref[j] = i > 0 ? pref[i - 1] : 0;
        //     pref[j] += p[j] + dist(0, p[j]);
        // }
    }
    for (int i = n - 1; i >= 0; i--) {
        suff[i] = (L - p[i]) + dist(0, p[i]);
        if (i + k < n) suff[i] += suff[i + k];
        // for (int j = i; j >= max(0, i - k + 1); j--) {
        //     suff[j] = suff[i + 1];
        //     suff[j] += (L - p[j]) + dist(0, p[j]);
        // }
    }
    ll ans = min(pref[n - 1], suff[0]);
    for (int i = 1; i < n; i++) {
        ans = min(ans, pref[i - 1] + suff[i]);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 444 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 444 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 53 ms 29680 KB Output is correct
34 Correct 24 ms 21844 KB Output is correct
35 Correct 26 ms 22364 KB Output is correct
36 Correct 52 ms 29784 KB Output is correct
37 Correct 52 ms 29780 KB Output is correct
38 Correct 51 ms 29780 KB Output is correct
39 Correct 59 ms 28188 KB Output is correct
40 Correct 30 ms 23636 KB Output is correct
41 Correct 55 ms 30032 KB Output is correct
42 Correct 32 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 444 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 53 ms 29680 KB Output is correct
34 Correct 24 ms 21844 KB Output is correct
35 Correct 26 ms 22364 KB Output is correct
36 Correct 52 ms 29784 KB Output is correct
37 Correct 52 ms 29780 KB Output is correct
38 Correct 51 ms 29780 KB Output is correct
39 Correct 59 ms 28188 KB Output is correct
40 Correct 30 ms 23636 KB Output is correct
41 Correct 55 ms 30032 KB Output is correct
42 Correct 32 ms 23892 KB Output is correct
43 Correct 588 ms 292708 KB Output is correct
44 Correct 250 ms 215556 KB Output is correct
45 Correct 264 ms 223512 KB Output is correct
46 Correct 536 ms 293968 KB Output is correct
47 Correct 507 ms 293884 KB Output is correct
48 Correct 567 ms 293892 KB Output is correct
49 Correct 520 ms 278884 KB Output is correct
50 Correct 302 ms 232496 KB Output is correct
51 Correct 555 ms 293816 KB Output is correct
52 Correct 326 ms 235160 KB Output is correct