Submission #666919

#TimeUsernameProblemLanguageResultExecution timeMemory
666919Markomafko972Boxes with souvenirs (IOI15_boxes)C++14
100 / 100
585 ms332968 KiB
#include "boxes.h" #include <bits/stdc++.h> #define X first #define Y second #define pb push_back #define pii pair<int, int> typedef long long ll; using namespace std; const int MOD = 1e9 + 7; const ll INF = 1e18; const int OFF = (1 << 20); ll l[10000005]; ll r[10000005]; vector<int> v; long long delivery(int n, int k, int d, int p[]) { for (int i = 0; i < n; i++) { if (p[i] != 0) v.push_back(p[i]); } for (int i = 0; i < (int)v.size(); i++) { if (i < k) l[i] = 2LL*v[i]; else l[i] = 2LL*v[i]+l[i-k]; } for (int i = (int)v.size()-1; i >= 0; i--) { if ((int)v.size() - i <= k) r[i] = 2LL*(d-v[i]); else r[i] = 2LL*(d-v[i])+r[i+k]; } ll sol = min(r[0], l[(int)v.size()-1]); for (int i = 0; i < (int)v.size()-1; i++) { sol = min(sol, l[i]+r[i+1]); } for (int i = 0; i+k+1 < (int)v.size(); i++) { sol = min(sol, l[i]+r[i+k+1]+d); } sol = min(sol, l[(int)v.size()-k-1]+d); sol = min(sol, r[k]+d); return sol; }
#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...