제출 #41328

#제출 시각아이디문제언어결과실행 시간메모리
41328IvanCK개의 묶음 (IZhO14_blocks)C++14
100 / 100
249 ms12936 KiB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
const int INF = 1e9;
const int MAXN = 1e5  + 10;
int vetor[MAXN],dp[MAXN],novadp[MAXN],menor[MAXN],napilha[MAXN],N,K;
struct minStack{
	stack<ii> pilha;
	int menor;
	minStack(){menor = INF;}
	void push(int val){
		ii novo = ii(val,menor);
		menor = min(menor,val);
		pilha.push(novo);
	}
	void pop(){
		menor = pilha.top().second;
		pilha.pop();
	}
	bool empty(){return pilha.empty();}
	int getMin(){return menor;}
};
void solve(int k){
	for(int i = 0;i<=N;i++){
		novadp[i] = INF;
		napilha[i] = 0;
	}
	stack<int> pilha;
	minStack pq;
	for(int i = k;i<=N;i++){
		menor[i] = dp[i-1];
		while(!pilha.empty() && vetor[i] >= vetor[pilha.top()]){
			menor[i] = min(menor[i],menor[pilha.top()]);
			napilha[pilha.top()] = 0;
			pilha.pop();
			pq.pop();
		}
		pq.push(menor[i] + vetor[i]);
		pilha.push(i);
		napilha[i] = 1;
		if(!pq.empty()) novadp[i] = pq.getMin();
	}
	for(int i = 1;i<=N;i++) dp[i] = novadp[i];
	while(!pilha.empty()) pilha.pop();
	while(!pq.empty()) pq.pop();
}
int main(){
	scanf("%d %d",&N,&K);
	vetor[0] = dp[0] = INF;
	for(int i = 1;i<=N;i++){
		scanf("%d",&vetor[i]);
	}
	dp[1] = vetor[1];
	for(int i = 2;i<=N;i++) dp[i] = max(dp[i-1],vetor[i]);
	for(int k = 2;k<=K;k++) solve(k);
	printf("%d\n",dp[N]);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

blocks.cpp: In function 'int main()':
blocks.cpp:48:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&K);
                      ^
blocks.cpp:51:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&vetor[i]);
                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...