Submission #787034

#TimeUsernameProblemLanguageResultExecution timeMemory
787034GusterGoose27Boxes with souvenirs (IOI15_boxes)C++17
20 / 100
1 ms212 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e7+5; ll pre[MAXN]; ll delivery(int n, int k, int l, int p[]) { ll cur = 0; int res = 0; int s = 0; for (int i = 0; i < n && p[i] <= l/2; i++) { pre[i] = cur+2*p[i]; if (res == k-1) { cur += 2*p[i]; res = 0; continue; } res++; } cur = 0; res = 0; for (int i = n-1; i >= 0 && p[i] > l/2; i--) { pre[i] = cur+2*(l-p[i]); if (res == k-1) { cur += 2*(l-p[i]); res = 0; continue; } res++; } int div; for (div = 0; div < n && p[div] <= l/2; div++) {} ll ans = (div ? pre[div-1] : 0) + pre[div]; for (int i = div-k+1; i < div; i++) { int lp = max(i, 0); int rp = min(n-1, i+k-1); ans = min(ans, (lp ? pre[lp-1] : 0)+pre[rp+1]+l); } return ans; }

Compilation message (stderr)

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:14:9: warning: unused variable 's' [-Wunused-variable]
   14 |     int s = 0;
      |         ^
#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...