Submission #780218

#TimeUsernameProblemLanguageResultExecution timeMemory
780218vjudge1Boxes with souvenirs (IOI15_boxes)C++17
35 / 100
1 ms212 KiB
#include "boxes.h" #include<bits/stdc++.h> using namespace std; #define pb push_back #define pii pair<long long, long long> #define st first #define nd second #define sp " " #define endl "\n" #define ll long long long long delivery(int N, int K, int L, int p[]) { int n = N, k = K, l = L; sort(p, p + n); ll curr = 0; for (int i = 0; i < n; i += k){ int to = min(n - 1, i + k - 1); if (p[to] <= L / 2){ curr += 2 * p[to]; } else if (p[i] >= L / 2){ curr += 2 * (L - p[i]); } else curr += L; } ll ans = curr; curr = 0; int pos = 0; while(pos < n && p[pos] < L / 2) pos++; do{ for (int i = pos - 1; i >= 0; i -= k){ int to = max(0, i - k + 1); curr += 2 * min(p[i], L / 2); } for (int i = pos; i < n; i += k){ int to = min(n - 1, i + k - 1); curr += 2 * (L - p[i]); } ans = min(ans, curr); curr = 0; pos++; } while(pos < n && p[pos] <= L / 2); reverse(p, p + n); for (int i = 0; i < n; i += k){ int to = min(n - 1, i + k - 1); if (p[i] <= L / 2){ curr += 2 * p[i]; } else if (p[to] >= L / 2){ curr += 2 * (L - p[to]); } else curr += L; } return min(ans, curr); }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:34:17: warning: unused variable 'to' [-Wunused-variable]
   34 |             int to =  max(0, i - k + 1);
      |                 ^~
boxes.cpp:39:17: warning: unused variable 'to' [-Wunused-variable]
   39 |             int to =  min(n - 1, i + k - 1);
      |                 ^~
boxes.cpp:13:23: warning: unused variable 'l' [-Wunused-variable]
   13 |     int n = N, k = K, l = L;
      |                       ^
#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...