Submission #1100926

#TimeUsernameProblemLanguageResultExecution timeMemory
1100926akzytrStove (JOI18_stove)C++17
20 / 100
1 ms504 KiB
#include <bits/stdc++.h> using namespace std; template <typename T> using ve = vector<T>; template <typename T, int sz> using ar = array<T, sz>; typedef long long ll; #define pb push_back #define fi first #define se second #define endl '\n' int main() { int N, K; cin >> N >> K; int ti[22] = {}; for(int i = 0; i < N; i++) { int x; cin >> x; ti[x] = 1; } int dp[22][22][2]; for(int i = 0; i < 22; i++) { for(int j = 0; j < 22; j++) { dp[i][j][0] = (int)1e9; dp[i][j][1] = (int)1e9; } } for(int i = 21; i >= 1; i--) { if(ti[i]) { break; } for(int k = 0; k <= K; k++) { dp[i][k][0] = 0; } } for(int i = 21; i >= 1; i--) { for(int left = K; left >= 1; left--) { // ON if(ti[i]) { for(int j = i + 1; j <= 21; j++) { dp[i][left][1] = min(dp[i][left][1], dp[j][left - 1][0] + j - i); } } else { for(int j = i + 1; j <= 21; j++) { if(ti[j] == 1) { dp[i][left][0] = min(dp[i][left][0], dp[j][left][1]); break; } } } } } cout << min(dp[1][K][0], dp[1][K][1]) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...