| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1288085 | datluong_04 | K개의 묶음 (IZhO14_blocks) | C++20 | 165 ms | 80876 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i , a , b) for(int i = a ; i <= b; i++)
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define maxn 100005
#define maxk 105
#define pli pair<ll,int>
ll dp[maxk][maxn] , a[maxn];
int main(){
if(fopen("blocks.in" , "r")){
freopen("blocks.in" ,"r" , stdin);
freopen("blocks.out" , "w" , stdout);
}
FAST;
int n , k;
cin >> n >> k;
FOR(i , 1 , n) cin >> a[i];
FOR(i , 0 , k) FOR(j , 0 , n) dp[i][j] = 1e18;
dp[1][0] = 0;
dp[0][0] = 0;
FOR(i , 1 , n) dp[1][i] = max(dp[1][i - 1] , a[i]);
FOR(i , 2 , k){
stack<pli> st;
FOR(j , 2 , n){
ll minF = dp[i - 1][j - 1];
while(!st.empty() && a[st.top().second] <= a[j]){
minF = min(minF , st.top().first);
st.pop();
}
dp[i][j] = min(dp[i][st.empty() ? 0 : st.top().second] , minF + a[j]);
st.push(make_pair(minF , j));
}
}
cout << dp[k][n];
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
