Submission #100197

#TimeUsernameProblemLanguageResultExecution timeMemory
100197luciocfBoxes with souvenirs (IOI15_boxes)C++14
50 / 100
2047 ms33528 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; const int maxn = 1e7+10; typedef long long ll; int p[maxn]; ll pref[maxn], suf[maxn]; long long delivery(int N, int K, int L, int positions[]) { int n = N, k = K; for (int i = 1; i <= n; i++) p[i] = positions[i-1]; pref[1] = 2ll*p[1]; for (int i = 2; i <= n; i++) pref[i] = 2ll*p[i] + pref[max(0, i-k)]; suf[n] = 2ll*(L-p[n]); for (int i = n-1; i >= 1; i--) suf[i] = 2ll*(L-p[i]) + suf[min(n+1, i+k)]; int add = n/k; if (n%k) add++; ll ans = min({pref[n], suf[1], 1ll*add*L}); for (int i = 1; i < n; i++) { int add = (n-i)/k; if ((n-i)%k) add++; ans = min(ans, pref[i] + 1ll*add*L); } for (int i = n; i > 1; i--) { int add = (i-1)/k; if ((i-1)%k) add++; ans = min(ans, suf[i] + 1ll*add*L); } for (int i = 1; i < n; i++) { for (int j = i+1; j <= n; j++) { int add = (j-i-1)/k; if ((j-i-1)%k) add++; ans = min(ans, pref[i] + suf[j] + 1ll*add*L); } } return ans; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:34:7: warning: declaration of 'add' shadows a previous local [-Wshadow]
   int add = (n-i)/k;
       ^~~
boxes.cpp:28:7: note: shadowed declaration is here
   int add = n/k;
       ^~~
boxes.cpp:42:7: warning: declaration of 'add' shadows a previous local [-Wshadow]
   int add = (i-1)/k;
       ^~~
boxes.cpp:28:7: note: shadowed declaration is here
   int add = n/k;
       ^~~
boxes.cpp:52:8: warning: declaration of 'add' shadows a previous local [-Wshadow]
    int add = (j-i-1)/k;
        ^~~
boxes.cpp:28:7: note: shadowed declaration is here
   int add = n/k;
       ^~~
#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...