Submission #464330

#TimeUsernameProblemLanguageResultExecution timeMemory
464330sumit_kk10Boxes with souvenirs (IOI15_boxes)C++14
0 / 100
13 ms15884 KiB
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define ll long long int #define ld long double using namespace std; const int MOD = 1e9 + 7; long long delivery(int N, int K, int L, int positions[]){ int n = N, k = K, l = L; sort(positions + 1, positions + n + 1); long long pre_dp[n + 2][k + 1], suf_dp[n + 2][k + 1]; for(int j = 1; j <= k; ++j) pre_dp[1][j] = 2*positions[1]; for(int i = 2; i <= n; ++i){ for(int j = 1; j <= k; ++j){ pre_dp[i][j] = INT_MAX; if(j == 1) pre_dp[i][j] = min(pre_dp[i][j], pre_dp[i - 1][k] + 2*positions[i]); else pre_dp[i][j] = min(pre_dp[i][j], pre_dp[i - 1][j - 1] + 2*(positions[i] - positions[i - 1])); } } for(int i = 1; i <= n; ++i){ int x = l - positions[i]; positions[i] = x; } for(int j = 1; j <= k; ++j){ suf_dp[n][j] = 2*positions[n]; suf_dp[n + 1][j] = 0; pre_dp[0][j] = 0; } for(int i = n - 1; i >= 1; --i){ for(int j = 1; j <= k; ++j){ suf_dp[i][j] = INT_MAX; if(j == 1) suf_dp[i][j] = min(suf_dp[i][j], suf_dp[i + 1][k] + 2*positions[i]); else suf_dp[i][j] = min(suf_dp[i][j], suf_dp[i + 1][j - 1] + 2*(positions[i] - positions[i + 1])); } } ll ans = INT_MAX; for(int i = 1; i <= n; ++i){ ll mn = INT_MAX; for(int j = 1; j <= k; ++j) mn = min(mn, suf_dp[i + 1][j]); for(int j = 1; j <= k; ++j) ans = min(ans, pre_dp[i][j] + mn); } return ans; }
#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...