제출 #65238

#제출 시각아이디문제언어결과실행 시간메모리
65238daniel_02선물상자 (IOI15_boxes)C++17
25 / 100
2 ms452 KiB
#include "boxes.h" #include <bits/stdc++.h> #define ll long long using namespace std; ll f(int x, int N, int L, int K, int p[]) { ll cur = 0, ans = 1LL * 1e18 + 7; for (int j = x; j >= 0; j -= K) { if (p[j] <= L / 2) cur += (p[j] * 2); else { if (j - K + 1 >= 0) { cur += min((L - p[j - K + 1]) * 2, L); } else { if (p[0] > L / 2) cur += min((L - p[0]) * 2, L); else cur += L; } } } for (int j = x + 1; j < N; j += K) { if (p[j] > L / 2) { cur += ((L - p[j]) * 2); } else { if (j + K - 1 < N) { cur += min(p[j + K - 1] * 2, L); } else { if (p[N - 1] <= L / 2) cur += min(p[N - 1] * 2, L); else cur += L; } } } ans = min(ans, cur); cur = 0; for (int j = x; j < N; j += K) { if (p[j] > L / 2) { cur += ((L - p[j]) * 2); } else { if (j + K - 1 < N) { cur += min(p[j + K - 1] * 2, L); } else { if (p[N - 1] <= L / 2) cur += min(p[N - 1] * 2, L); else cur += L; } } } for (int j = x - 1; j >= 0; j -= K) { if (p[j] <= L / 2) cur += (p[j] * 2); else { if (j - K + 1 >= 0) { cur += min((L - p[j - K + 1]) * 2, L); } else { if (p[0] > L / 2) cur += min((L - p[0]) * 2, L); else cur += L; } } } ans = min(ans, cur); return ans; } long long delivery(int N, int K, int L, int p[]) { long long ans; ans = 1LL * 1e18 + 7; int l = 0, r = N - 1; while (r - l > 1) { int mid = l + ((r - l) / 3), mid1 = r - ((r - l) / 3); if (f(mid, N, L, K, p) > f(mid1, N, L, K, p)) l = mid1; else r = mid; } ans = min(ans, f(l, N, L, K, p)); if (l + 1 < N) ans = min(ans, f(l + 1, N, L, K, p)); return ans; }
#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...