Submission #1044970

#TimeUsernameProblemLanguageResultExecution timeMemory
1044970vaneaBoxes with souvenirs (IOI15_boxes)C++14
10 / 100
1 ms348 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; using ll = long long; using ld = long double; const ll INF = 1e18; ll delivery(int n, int k, int l, int p[]) { vector<ll> dp1(n+1), dp2(n+2); ll ans = INF; for(int i = 1; i <= n; i++) { int last = max(0, i-k); ll lastP = (last ? p[last-1] : 0); ll lastP1 = (i-1 ? p[i-2] : 0); dp1[i] = dp1[last] + lastP*2 + p[i-1]-lastP; } for(int i = n; i >= 1; i--) { int last = min(n+1, i+k); ll lastP = (last != n+1 ? (l-p[last]) : 0); ll lastP1 = (last != n+1 ? p[last] : l); dp2[i] = dp2[last] + 2*lastP + lastP1-p[i-1]; } for(int i = 0; i <= n; i++) { ll add1 = 0, add2 = 0; if(i) add1 = min((ll)p[i-1], (ll)l-p[i-1]); if(i != n) add2 = min(p[i], l-p[i]); ans = min(ans, add1+add2+dp1[i]+dp2[i+1]); } return ans; } /* int main() { int arr[5] = {1,2,5}; cout << delivery(3, 2, 8, arr); }*/

Compilation message (stderr)

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:15:12: warning: unused variable 'lastP1' [-Wunused-variable]
   15 |         ll lastP1 = (i-1 ? p[i-2] : 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...