답안 #331079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331079 2020-11-27T08:56:29 Z Gurban K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = 1e2+5;
const int maxn=1e5+5;
int n,k,a[maxn];
ll dp[N][maxn];
stack<pair<int,ll>>s;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	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],1ll*a[i]);

	for(int i = 2;i <= k;i++){
		dp[i][i] = dp[i-1][i-1]+a[i];
		s.push({i,dp[i][i]});
		for(int j = i+1;j <= n;j++){
			while(!s.empty() and a[s.top().first] <= a[j]) s.pop();
			if(!s.empty()){
				ll nw = a[j] + dp[i-1][s.top().first];
				s.push({j,min(nw,s.top().second)});
			}
			else s.push({j,dp[i-1][i-1]+a[j]});
			dp[i][j] = s.top().second;
		}
	}
	cout<<dp[k][n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -