Submission #793464

#TimeUsernameProblemLanguageResultExecution timeMemory
793464MarkynoodleBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
2 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long ll delivery(int n, int k, int l, int posin[]){ vector<int> pos(n); for(int i =0; i<n ;i++){ pos[i] = posin[i]; } if(k == 1){ ll s = 0; for(auto k : pos)s += min(k*2, (l - k)*2); return s; } ll sol = 1e16; sort(pos.begin(), pos.end()); for(int i = 0; i<=n; i++){ ll tempsol = 0; int cnt = 0; int cycle = 0; while(cnt < i){ if(cnt + 1 == i){ tempsol += pos[cnt]; tempsol += min(pos[cnt], l - pos[cnt]); break; } if(cycle == k){ tempsol += pos[cnt]; tempsol += min(pos[cnt], l - pos[cnt]); cycle = 0; } cnt++; cycle++; } //cout<<tempsol<<" "; cnt = n; cycle = 0; while(cnt >= i){ if(cnt == i + 1){ tempsol += l - pos[cnt]; tempsol += min(pos[cnt], l - pos[cnt]); break; } if(cycle == k){ tempsol += l - pos[cnt]; tempsol += min(pos[cnt], l - pos[cnt]); cycle = 0; } cnt--; cycle++; } sol = min(sol, tempsol); //cout<<tempsol<<"_"; } return sol; } /* int main(){ int in[] = {2}; cout<<delivery(1, 1, 10, in)<<"\n"; in[0] = 4; cout<<delivery(1, 1, 10, in)<<"\n"; } */

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:15:18: warning: declaration of 'auto k' shadows a parameter [-Wshadow]
   15 |         for(auto k : pos)s += min(k*2, (l - k)*2);
      |                  ^
boxes.cpp:8:24: note: shadowed declaration is here
    8 | ll delivery(int n, int k, int l, int posin[]){
      |                    ~~~~^
#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...