답안 #777513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777513 2023-07-09T09:56:16 Z boris_mihov 선물상자 (IOI15_boxes) C++17
100 / 100
712 ms 372468 KB
#include "boxes.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 10000000 + 10;
const llong INF = 1e18;

int n, k, l;
std::vector <int> left;
std::vector <int> right;
llong prefix[MAXN];
llong suffix[MAXN];

llong delivery(int N, int K, int L, int p[]) 
{
    n = N;
    k = K;
    l = L;

    if (k > n) k = n;
    for (int i = 0 ; i < n ; ++i)
    {
        left.push_back(p[i]);
        right.push_back(l - p[i]);
    }

    for (int i = 0 ; i < n ; ++i)
    {
        prefix[i] = 2 * left[i];
        if (i >= k) prefix[i] += prefix[i - k];
    }

    for (int i = n - 1 ; i >= 0 ; --i)
    {
        suffix[i] = 2 * right[i];
        if (i + k < n) suffix[i] += suffix[i + k];
    }

    llong ans = suffix[0];
    for (int i = 0 ; i < n ; ++i)
    {
        ans = std::min(ans, prefix[i] + suffix[i + 1]);
    }
    
    for (int i = 0 ; i + k <= n ; ++i)
    {
        llong curr = l + suffix[i + k];
        if (i > 0) curr += prefix[i - 1];
        ans = std::min(ans, curr);
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 58 ms 27980 KB Output is correct
34 Correct 26 ms 27892 KB Output is correct
35 Correct 28 ms 27864 KB Output is correct
36 Correct 53 ms 37632 KB Output is correct
37 Correct 57 ms 37676 KB Output is correct
38 Correct 55 ms 37624 KB Output is correct
39 Correct 51 ms 36196 KB Output is correct
40 Correct 32 ms 31564 KB Output is correct
41 Correct 53 ms 37608 KB Output is correct
42 Correct 33 ms 31728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 58 ms 27980 KB Output is correct
34 Correct 26 ms 27892 KB Output is correct
35 Correct 28 ms 27864 KB Output is correct
36 Correct 53 ms 37632 KB Output is correct
37 Correct 57 ms 37676 KB Output is correct
38 Correct 55 ms 37624 KB Output is correct
39 Correct 51 ms 36196 KB Output is correct
40 Correct 32 ms 31564 KB Output is correct
41 Correct 53 ms 37608 KB Output is correct
42 Correct 33 ms 31728 KB Output is correct
43 Correct 591 ms 371224 KB Output is correct
44 Correct 287 ms 294180 KB Output is correct
45 Correct 309 ms 301896 KB Output is correct
46 Correct 578 ms 372468 KB Output is correct
47 Correct 712 ms 371196 KB Output is correct
48 Correct 601 ms 372200 KB Output is correct
49 Correct 599 ms 356664 KB Output is correct
50 Correct 381 ms 310944 KB Output is correct
51 Correct 636 ms 369076 KB Output is correct
52 Correct 404 ms 312292 KB Output is correct