Submission #791743

#TimeUsernameProblemLanguageResultExecution timeMemory
791743JosiaBoxes with souvenirs (IOI15_boxes)C++17
0 / 100
1 ms212 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; long long delivery(int N, int K, int L, int p[]) { int res = 0; map<int, int> poss; for (int i = 0; i<N; i++) { poss[p[i]]++; } int cnt = 0; int startPos = (*poss.begin()).first; int dist; while (poss.size()) { dist = (*poss.begin()).first; poss[(*poss.begin()).first]--; if (poss[(*poss.begin()).first] == 0) poss.erase(poss.begin()); cnt++; if (cnt == K) { if (dist > L/2 && startPos < L/2) res += L; else res += min(dist*2, (L-dist)*2); startPos = (*poss.begin()).first; cnt = 0; } } if (dist > L/2 && startPos < L/2) res += L; else res += min(dist*2, (L-dist)*2); startPos = (*poss.begin()).first; cnt = 0; // cerr << res << "\n"; return res; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:31:25: warning: 'dist' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |     else res += min(dist*2, (L-dist)*2);
      |                     ~~~~^~
#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...