답안 #134123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134123 2019-07-22T06:12:34 Z mirbek01 K개의 묶음 (IZhO14_blocks) C++11
0 / 100
71 ms 14328 KB
# include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e5 + 2;
 
int n, a[N], k, dp[102][N];
int stk[N], pt, pf[N];
 
int main(){
	
	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 ++){
		pt = 0;
		for(int j = i; j <= n; j ++){
			while(pt > 0 && a[ stk[pt] ] < a[j])
				pt --;
			stk[++ pt] = j;
			pf[pt] = dp[i - 1][ max(stk[pt - 1] + 1, i - 1) ] + a[j];
			if(pt > 1)
				pf[pt] = min(pf[pt - 1], pf[pt]);
			dp[i][j] = pf[pt];/*
			int mx = 0;
			for(int t = j; t >= i; t --){
				mx = max(mx, a[t]);
				dp[i][j] = min(dp[i][j], dp[i - 1][t - 1] + mx);
			}*/
		}/*
		for(int j = 1; j <= n; j ++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
		*/
	}
	
	cout << dp[k][n] << endl;
}	
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1500 KB Output is correct
2 Correct 27 ms 1016 KB Output is correct
3 Correct 31 ms 2044 KB Output is correct
4 Incorrect 71 ms 14328 KB Output isn't correct
5 Halted 0 ms 0 KB -