Submission #702109

#TimeUsernameProblemLanguageResultExecution timeMemory
702109GrandTiger1729K blocks (IZhO14_blocks)C++17
53 / 100
1079 ms1364 KiB
#include <iostream> #include <deque> #include <set> #include <cassert> using namespace std; const int INF = 1e9; int main(){ cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; int a[n + 1]{}; for (int i = 1; i <= n; i++){ cin >> a[i]; } int dp[n + 1][m + 1]{}; fill_n(&dp[0][0], sizeof(dp) / sizeof(int), INF); deque<int> dq; a[0] = INF; dp[0][0] = 0; dq.push_back(0); multiset<int> st[m + 1]{}; for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ int cur = a[i]; for (int k = i - 1; k >= 0; k--){ dp[i][j] = min(dp[i][j], dp[k][j - 1] + cur); cur = max(cur, a[k]); } } // while (dq.size() && a[dq.back()] < a[i]){ // int k = dq.back(); // dq.pop_back(); // for (int j = 1; j <= m; j++){ // assert(st[j - 1].find(dp[dq.back()][j - 1] + a[k]) != st[j - 1].end()); // st[j - 1].erase(st[j - 1].find(dp[dq.back()][j - 1] + a[k])); // } // } // for (int j = 1; j <= m; j++){ // st[j - 1].insert(dp[dq.back()][j - 1] + a[i]); // dp[i][j] = *st[j - 1].begin(); // } // dq.push_back(i); } cout << dp[n][m] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...