# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
63913 | 2018-08-03T06:53:21 Z | Kubalionzzale | 선물상자 (IOI15_boxes) | C++14 | 2 ms | 376 KB |
#include "boxes.h" #include <map> #include <iostream> #include <algorithm> long long delivery(int n, int k, int l, int p[]) { if (n == 1) { return std::min(p[0] * 2LL, (l - p[0]) * 2LL); } int here = n; for (int i = 0; i < n; ++i) { if (p[i] > l - p[i] && here == n) { here = i; } if (i >= here) { p[i] = l - p[i]; } } if (here == 0) { long long int sumleft = p[0], leftleft = -1; int cur = k - 1; for (int i = 1; i < n; ++i) { if (cur == 0) { sumleft += p[i - 1] + p[i] * 1LL; cur = k - 1; } else { sumleft += p[i - 1] - p[i] * 1LL; --cur; } } sumleft += p[n - 1] * 1LL; return sumleft; } else if (here == n) { long long int sumright = p[here - 1], leftright = -1; int cur = k - 1; for (int i = here - 2; i >= 0; --i) { if (cur == 0) { sumright += p[i + 1] + p[i] * 1LL; cur = k - 1; } else { sumright += p[i + 1] - p[i] * 1LL; --cur; } } sumright += p[0] * 1LL; return sumright; } long long int sumleft = p[here - 1], leftleft = -1; int cur = k - 1; for (int i = here - 2; i >= 0; --i) { if (cur == 0) { sumleft += p[i + 1] + p[i] * 1LL; cur = k - 1; } else { sumleft += p[i + 1] - p[i] * 1LL; --cur; } } sumleft += p[0] * 1LL; long long int sumright = p[here], leftright = -1; cur = k - 1; for (int i = here + 1; i < n; ++i) { if (cur == 0) { sumright += p[i - 1] + p[i] * 1LL; cur = k - 1; } else { sumright += p[i - 1] - p[i] * 1LL; --cur; } } sumright += p[n - 1] * 1LL; leftright = cur; long long int curmin = sumleft + sumright; if (k == 1) return curmin; long long int curval, max = 0; int where = std::max(here - k + 1, 0); for (int i = std::max(here - k + 1, 0);; ++i) { if (i >= here) break; if (i + k - 1 >= n) break; curval = 0; if (i - 1 > 0) { curval += p[i] - p[i - 1] * 1LL; } else { curval += p[i] * 1LL; } if (i + k < n) { if (i + k == here) { curval += (l - p[i + k]) * 1LL - p[i + k - 1]; } else { curval += p[i + k - 1] - p[i + k] * 1LL; } } else { curval += p[i + k - 1] * 1LL; } if (curval > max) { max = curval; where = i; } } long long int cursum = l; if (where != 0) { cur = k - 1; cursum += p[where - 1] * 1LL; for (int i = where - 2; i >= 0; --i) { if (cur == 0) { cursum += p[i + 1] + p[i] * 1LL; cur = k - 1; } else { cursum += p[i + 1] - p[i] * 1LL; --cur; } } cursum += p[0] * 1LL; } if (where + k - 1 != n - 1) { cur = k - 1; cursum += p[where + k] * 1LL; for (int i = where + k + 1; i < n; ++i) { if (cur == 0) { cursum += p[i - 1] + p[i] * 1LL; cur = k - 1; } else { cursum += p[i - 1] - p[i] * 1LL; --cur; } } cursum += p[n - 1] * 1LL; } return std::min(curmin, cursum); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 348 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 252 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 348 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 348 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 252 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 2 ms | 256 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 348 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 256 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 256 KB | Output is correct |
25 | Correct | 2 ms | 256 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Incorrect | 2 ms | 348 KB | Output isn't correct |
28 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 348 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 252 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 2 ms | 256 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 348 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 256 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 256 KB | Output is correct |
25 | Correct | 2 ms | 256 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Incorrect | 2 ms | 348 KB | Output isn't correct |
28 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 348 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 252 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 2 ms | 256 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 348 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 256 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 256 KB | Output is correct |
25 | Correct | 2 ms | 256 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Incorrect | 2 ms | 348 KB | Output isn't correct |
28 | Halted | 0 ms | 0 KB | - |