제출 #787023

#제출 시각아이디문제언어결과실행 시간메모리
787023GusterGoose27선물상자 (IOI15_boxes)C++17
20 / 100
1 ms308 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll delivery(int n, int k, int l, int p[]) { ll opa = 0; int res = 0; int s = 0; for (int i = 0; i < n; i++) { // if (k == 1) { // opa += min(p[i], l-p[i]); // continue; // } if (res == k-1 || i == n-1) { if (res == 0) s = p[i]; if (s <= l/2) { opa += min(l, 2*p[i]); } else { opa += 2*(l-s); } res = 0; continue; } if (res == 0) { s = p[i]; res++; continue; } res++; } if (k == 1) return opa; ll opb = 0; res = 0; s = 0; for (int i = n-1; i >= 0; i--) { if (res == k-1 || i == 0) { if (res == 0) s = p[i]; if (s > l/2) { opb += min(l, 2*(l-p[i])); } else { opb += 2*s; } res = 0; continue; } if (res == 0) { s = p[i]; res++; continue; } res++; } ll opc = 0; res = 0; for (int i = 0; i < n && p[i] <= l/2; i++) { if (res == k-1 || i == n-1 || p[i+1] > l/2) { opc += 2*p[i]; res = 0; continue; } res++; } for (int i = n-1; i >= 0 && p[i] > l/2; i--) { if (res == k-1 || i == 0 || p[i-1] <= l/2) { opc += 2*(l-p[i]); res = 0; continue; } res++; } return min(min(opa, opa), opc); }
#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...