Submission #1306021

#TimeUsernameProblemLanguageResultExecution timeMemory
1306021annnK blocks (IZhO14_blocks)C++20
0 / 100
33 ms81024 KiB
// Problem: K blocks // Contest: Virtual Judge - OJUZ // URL: https://vjudge.net/problem/OJUZ-IZhO14_blocks#author=0 // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define pb push_back #define ff first #define ss second #define ii pair<int, int> #define vi vector<int> #define vii vector<pair<int, int>> #define yes cout << "YES\n" #define no cout << "NO\n" #define mii map<int, int> #define rep(i, a, b) for (int i = a; i <= b; i++) #define all(a, len) (a) + 1, (a) + len + 1 #define vall(a) (a).begin(), a.end() const int INF = 4e18; const int MOD = 1e9 + 7; int n, k; const int mx = 1e5 + 3, mxk = 103; int a[mx], dp[mxk][mx]; void TheEminemShow() { cin >> n >> k; rep(i, 1, n) cin >> a[i]; } void Recovery() { fill(&dp[0][0], &dp[0][0] + mxk*mx, INF); dp[0][0] = 0; for (int i = 1; i <= n; i++) { stack<ii> st; rep(j, 1, n) { int mindp = dp[i-1][j-1]; while (st.size() && a[st.top().ff] <= a[i]) { mindp = min(mindp, st.top().ss); st.pop(); } if (st.size()) { dp[i][j] = min(dp[i-1][st.top().ff], mindp + a[j]); } else { dp[i][j] = min(dp[i-1][0], mindp) + a[j]; } st.push({i, mindp}); } } cout << dp[k][n]; } void Kamikaze() { } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int TEST = 1; // cin >> TEST; while (TEST--) { TheEminemShow(); Recovery(); Kamikaze(); } 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...