Submission #1145238

#TimeUsernameProblemLanguageResultExecution timeMemory
1145238thangdz2k7선물상자 (IOI15_boxes)C++20
50 / 100
2095 ms13564 KiB
#ifdef EVAL #include "boxes.h" #endif // EVAL #include <bits/stdc++.h> using namespace std; const int MaxN = 1e7; const long long inf = 1e18; int pos[MaxN], n, k, len; long long dp[MaxN]; int cost(int le, int ri){ if (pos[ri] <= len / 2) return pos[ri] * 2; if (pos[le] > len / 2) return (len - pos[le]) * 2; return len; } long long delivery(int N, int K, int L, int position[]){ n = N, k = K, len = L; for (int i = 0; i < n; ++ i) pos[i] = position[i]; for (int i = 0; i < n; ++ i){ dp[i] = inf; for (int j = max(0, i - k + 1); j <= i; ++ j){ long long tmp = 0; if (j) tmp = dp[j - 1]; dp[i] = min(dp[i], tmp + cost(j, i)); } } return dp[n - 1]; } #ifndef EVAL int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k >> len; for (int i = 0; i < n; ++ i) cin >> pos[i]; cout << delivery(n, k, len, pos); } /* 10 1 5 0 0 0 0 0 1 3 3 3 4 */ #endif // EVAL
#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...