Submission #117500

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
1175002019-06-16 09:25:47zubecBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
551 ms221148 KiB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 10000005;
long long dp[N], dp2[N];
long long delivery(int N, int K, int L, int p[]) {
int mid = L/2;
int lstPos = -1;
for (int i = 1; i <= N; i++){
int pos = p[i-1];
dp[i] = dp[max(0, i-K)] + min(L, pos*2);
}
long long ans = 1e18;
for (int i = N; i >= 1; i--){
int pos = p[i-1];
dp2[i] = dp2[min(N+1, i+K)] + min(L, (L-pos)*2);
ans = min(ans, dp[i]+dp2[i+1]);
}
ans = min(ans, dp[0]+dp2[1]);
return ans;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:9:48: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 long long delivery(int N, int K, int L, int p[]) {
                                                ^
boxes.cpp:5:11: note: shadowed declaration is here
 const int N = 10000005;
           ^
boxes.cpp:11:9: warning: unused variable 'mid' [-Wunused-variable]
     int mid = L/2;
         ^~~
boxes.cpp:12:9: warning: unused variable 'lstPos' [-Wunused-variable]
     int lstPos = -1;
         ^~~~~~
#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...