답안 #885090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885090 2023-12-09T01:59:45 Z vjudge1 K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 600 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define read() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define day() time_t now = time(0);char* x = ctime(&now);cerr<<"Right Now Is : "<<x<<"\n"
 
#define ii pair<int,int>
#define X first
#define Y second 
 
const long long MAX = (int)1e5 + 5;
const long long INF = (int)1e9;
const long long MOD = (int)1e9 + 7;
 
int n,k;
int a[MAX];
int dp[2][MAX];
signed main(){
	
	read();
	
	cin >> n >> k;
	
	int bit = 0;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
		dp[bit][i] = INF;
	}
 
	for(int j = 1;j <= k;j++){
		bit = 1 - bit;
		stack<ii> st;
		for(int i = 1;i <= n;i++){
			
			if(i < j)continue;
			int summ = dp[1 - bit][i - 1];
 		
			// if(st.size())
				// cout << i << " " << st.size() << " " << a[st.top().X] << " " << a[i] << "\n";
			while(!st.empty() && a[st.top().X] <= a[i]){
				summ = min(summ,st.top().Y);
			//	cout << st.top().X << "\n";
				st.pop();
			}
			
			//cout << summ << " " << a[i] << ' ';
			dp[bit][i] = summ + a[i];
			
			if(!st.empty()){
				dp[bit][i] = min(dp[bit][i],a[st.top().X] + st.top().Y);
			}
			
			
			
			st.push({i,summ});
			//cout << dp[bit][i] << " ";
		}
		
		for(int i = 1;i <= n;i++){
			dp[1 - bit][i] = INF;
		}
		//cout << "\n";
	}
	
	cout << dp[bit][n];
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 600 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 356 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 600 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 600 KB Output isn't correct
14 Halted 0 ms 0 KB -