Submission #484736

#TimeUsernameProblemLanguageResultExecution timeMemory
484736imachugBoxes with souvenirs (IOI15_boxes)C++17
50 / 100
2087 ms29476 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; long long delivery(int n, int k, int l, int p[]) { vector<long long> dp_left(n + 1, 1e18); dp_left[0] = 0; for(int i = 1; i <= n; i++) { dp_left[i] = dp_left[max(0, i - k)] + 2 * p[i - 1]; } vector<long long> dp_right(n + 1, 1e18); dp_right[n] = 0; for(int i = n - 1; i >= 0; i--) { dp_right[i] = dp_right[min(n, i + k)] + 2 * (l - p[i]); } long long ans = 1e18; for(int i = 0; i <= n; i++) { for(int j = i; j <= n; j++) { ans = min(ans, dp_left[i] + dp_right[j] + (long long)(j - i + k - 1) / k * l); } } return ans; if(k == 1) { long long ans = 0; for(int i = 0; i < n; i++) { ans += min(p[i] * 2, (l - p[i]) * 2); } return ans; } if(k == n) { long long ans = l; for(int i = -1; i < n; i++) { ans = min(ans, (long long)(i == -1 ? 0 : p[i] * 2) + (long long)(i == n - 1 ? 0 : (l - p[i + 1]) * 2)); } return ans; } return 0; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:32:13: warning: declaration of 'ans' shadows a previous local [-Wshadow]
   32 |   long long ans = 0;
      |             ^~~
boxes.cpp:21:12: note: shadowed declaration is here
   21 |  long long ans = 1e18;
      |            ^~~
boxes.cpp:40:13: warning: declaration of 'ans' shadows a previous local [-Wshadow]
   40 |   long long ans = l;
      |             ^~~
boxes.cpp:21:12: note: shadowed declaration is here
   21 |  long long ans = 1e18;
      |            ^~~
#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...