답안 #157634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157634 2019-10-12T16:12:15 Z gemini_man K개의 묶음 (IZhO14_blocks) C++11
0 / 100
7 ms 4604 KB
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
using namespace std;
const int N = 100005;
const int K = 105;
const int INF = 2e9;
int n,k;
int dp[N][K];
int a[N];
int lf[N];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	up(i,1,n) cin >> a[i];
	up(i,0,n) up(j,0,k) dp[i][j] = INF;
	int curMax = 0;
	up(i,1,n){
		curMax = max(curMax, a[i]);
		dp[i][1] = curMax;
	}
 
	int s = 0;
	vector<int> sk;
	up(i,1,n){
		while (!sk.empty()) {
			if (a[sk.back()] < a[i]) sk.pop_back();
			else break;
		}
		if (!sk.empty()) lf[i] = sk.back() + 1;
		else lf[i] = 1;
		sk.push_back(i); 
	}
	for( int i = 2;i <= n;++i){
		for(int j = 2; j <= min(i,k) ;++j){
			dp[i][j] = min(dp[max(lf[i], j-1)][j-1] + a[i], dp[lf[i]-1][j]);
		}
	}
	cout << dp[n][k];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:25:6: warning: unused variable 's' [-Wunused-variable]
  int s = 0;
      ^
# 결과 실행 시간 메모리 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 380 KB Output is correct
5 Correct 7 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 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 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 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4604 KB Output isn't correct
2 Halted 0 ms 0 KB -