답안 #646984

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646984 2022-10-01T09:53:30 Z nandonathaniel K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXK=105,MAXN=100005;
int dp[MAXK][MAXN],a[MAXN];
typedef pair<int,int> pii;
 
//https://codeforces.com/blog/entry/18866
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int N,K;
	cin >> N >> K;
	for(int i=1;i<=N;i++)cin >> a[i];
	for(int i=1;i<=N;i++)dp[1][i]=max(dp[1][i-1],a[i]);
	for(int i=2;i<=K;i++){
		stack<pii> st;
		for(int j=i;j<=N;j++){
			int minDP=dp[i-1][j-1];
			while(!st.empty() && a[st.top().first]<=a[j]){
				minDP=st.top().second;
				st.pop();
			}
			int val=1e9;
			if(!st.empty())val=dp[i][st.top().first];
			dp[i][j]=min(val,minDP+a[j]);
			st.push({j,minDP});
		}
	}
	cout << dp[K][N] << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 260 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 260 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 260 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -