Submission #41326

# Submission time Handle Problem Language Result Execution time Memory
41326 2018-02-16T10:00:36 Z IvanC K blocks (IZhO14_blocks) C++14
0 / 100
25 ms 876 KB
#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;
void solve(int k){
	for(int i = 0;i<=N;i++){
		novadp[i] = INF;
		napilha[i] = 0;
	}
	stack<int> pilha;
	priority_queue<ii, vector<ii>, greater<ii> > 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.push(ii(menor[i] + vetor[i],i));
		pilha.push(i);
		napilha[i] = 1;
		while(!pq.empty() && !napilha[pq.top().second]){
			pq.pop();
		}
		if(!pq.empty()) novadp[i] = pq.top().first;
	}
	for(int i = 1;i<=N;i++) dp[i] = novadp[i];
}
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;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:32: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:35:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&vetor[i]);
                        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 424 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 496 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 1 ms 564 KB Output is correct
8 Correct 1 ms 692 KB Output is correct
9 Correct 1 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Incorrect 1 ms 692 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 692 KB Output is correct
2 Correct 1 ms 692 KB Output is correct
3 Correct 2 ms 692 KB Output is correct
4 Correct 2 ms 692 KB Output is correct
5 Correct 1 ms 692 KB Output is correct
6 Correct 1 ms 692 KB Output is correct
7 Correct 1 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 1 ms 692 KB Output is correct
10 Correct 1 ms 692 KB Output is correct
11 Incorrect 2 ms 692 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 876 KB Output isn't correct
2 Halted 0 ms 0 KB -