# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
63781 | 2018-08-02T18:41:09 Z | Kubalionzzale | 선물상자 (IOI15_boxes) | C++14 | 2 ms | 376 KB |
#include "boxes.h" #include <map> #include <iostream> #include <algorithm> long long int keepleft[10000010] = { 0 }, keepright[10000010] = { 0 }; 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) { int cur = k - 1; long long int sum = p[n - 1]; for (int i = n - 2; i >= 0; --i) { if (cur == 0) { sum += p[i + 1] * 2LL + p[i] - p[i + 1]; cur = k - 1; } else { sum += p[i] - p[i + 1] * 1LL; --cur; } } return sum + p[0] * 1LL; } else if (here == n) { int cur = k - 1; long long int sum = p[0]; for (int i = 1; i < n; ++i) { if (cur == 0) { sum += p[i - 1] * 2LL + p[i] - p[i - 1]; cur = k - 1; } else { sum += p[i] - p[i - 1] * 1LL; --cur; } } return sum + p[n - 1] * 1LL; } long long int sumleft = p[0], leftleft = -1; int cur = k - 1; for (int i = 1; i < here; ++i) { if (cur == 0) { sumleft += p[i - 1] * 2LL + p[i] - p[i - 1]; cur = k - 1; } else { sumleft += p[i] - p[i - 1] * 1LL; --cur; } keepleft[i] = sumleft; } sumleft += p[here - 1]; leftleft = cur; long long int sumright = p[n - 1], leftright = -1; cur = k - 1; for (int i = n - 2; i >= here; --i) { if (cur == 0) { sumright += p[i + 1] * 2LL + p[i] - p[i + 1]; cur = k - 1; } else { sumright += p[i] - p[i + 1] * 1LL; --cur; } keepright[i] = sumright; } sumright += p[here]; leftright = cur; long long int curmin = sumleft + sumright; long long int curleft = sumleft - p[here - 1]; cur = leftleft; bool flag = false; for (int i = here; i < n; ++i) { if (cur == 0) { curleft += p[i] * 2LL + keepright[i]; if (i == here) { curleft += p[i - 1] * 1LL - (l - p[i]); } else { curleft += p[i - 1] - p[i] * 1LL; } flag = true; break; } else { if (i == here) { curleft += p[i - 1] * 1LL - (l - p[i]); } else { curleft += p[i - 1] - p[i] * 1LL; } --cur; } } if (!flag) { curleft += p[n - 1] * 1LL; } if (leftleft == 0) curleft = 1e17; curmin = std::min(curmin, curleft); long long int curright = sumright - p[here]; cur = leftright; flag = false; for (int i = here - 1; i >= 0; --i) { if (cur == 0) { curright += p[i] * 2LL + keepleft[i]; if (i + 1 == here) { curright += (l - p[i + 1] * 1LL) - p[i]; } else { curright += p[i + 1] - p[i] * 1LL; } flag = true; break; } else { if (i + 1 == here) { curright += (l - p[i + 1] * 1LL) - p[i]; } else { curright += p[i + 1] - p[i] * 1LL; } --cur; } } if (!flag) { curright += p[0] * 1LL; } if (leftright == 0) curright = 1e17; curmin = std::min(curmin, curright); // std::cout << curleft << " " << curright << "\n"; return curmin; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 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 | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 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 | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Incorrect | 2 ms | 376 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 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 | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Incorrect | 2 ms | 376 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 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 | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Incorrect | 2 ms | 376 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |