Submission #84672

# Submission time Handle Problem Language Result Execution time Memory
84672 2018-11-16T13:10:00 Z farukkastamonuda K blocks (IZhO14_blocks) C++14
100 / 100
171 ms 51712 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define ii pair<int,int>
using namespace std;
int n,k,A[li],dp[105][li];
deque< pair<int,int> > q;
int main(){
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&A[i]);
	}
	for(int i=0;i<=k;i++){
		for(int j=0;j<=n;j++){
			dp[i][j]=inf;
		}
	}
	dp[0][0]=0;
	for(int i=1;i<=k;i++){
		q.clear();
		for(int j=1;j<=n;j++){
			if(i>j){
				dp[i][j]=inf;
				continue;
			}
			int s=dp[i-1][j-1];
			while(!q.empty() && q.front().fi<=A[j]){
				s=min(s,q.front().se);
				q.pop_front();
			}
			if(!q.empty() && q.front().fi+q.front().se<=s+A[j]){
				dp[i][j]=q.front().fi+q.front().se;
			}
			else{
				dp[i][j]=s+A[j];
				q.push_front(mp(A[j],s));
			}
		}
	}
	printf("%d\n",dp[k][n]);
	return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~
blocks.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&A[i]);
   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 0 ms 504 KB Output is correct
4 Correct 3 ms 584 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 608 KB Output is correct
7 Correct 2 ms 704 KB Output is correct
8 Correct 2 ms 708 KB Output is correct
9 Correct 2 ms 820 KB Output is correct
10 Correct 2 ms 820 KB Output is correct
11 Correct 2 ms 820 KB Output is correct
12 Correct 2 ms 820 KB Output is correct
13 Correct 2 ms 820 KB Output is correct
14 Correct 2 ms 820 KB Output is correct
15 Correct 2 ms 820 KB Output is correct
16 Correct 2 ms 820 KB Output is correct
17 Correct 2 ms 820 KB Output is correct
18 Correct 2 ms 820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 916 KB Output is correct
2 Correct 2 ms 916 KB Output is correct
3 Correct 2 ms 916 KB Output is correct
4 Correct 2 ms 996 KB Output is correct
5 Correct 2 ms 996 KB Output is correct
6 Correct 3 ms 996 KB Output is correct
7 Correct 2 ms 996 KB Output is correct
8 Correct 2 ms 996 KB Output is correct
9 Correct 2 ms 996 KB Output is correct
10 Correct 2 ms 996 KB Output is correct
11 Correct 2 ms 996 KB Output is correct
12 Correct 2 ms 996 KB Output is correct
13 Correct 2 ms 996 KB Output is correct
14 Correct 2 ms 996 KB Output is correct
15 Correct 2 ms 1012 KB Output is correct
16 Correct 2 ms 1016 KB Output is correct
17 Correct 2 ms 1020 KB Output is correct
18 Correct 2 ms 1024 KB Output is correct
19 Correct 2 ms 1028 KB Output is correct
20 Correct 2 ms 1032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1292 KB Output is correct
2 Correct 2 ms 1292 KB Output is correct
3 Correct 2 ms 1292 KB Output is correct
4 Correct 2 ms 1292 KB Output is correct
5 Correct 2 ms 1292 KB Output is correct
6 Correct 2 ms 1292 KB Output is correct
7 Correct 2 ms 1292 KB Output is correct
8 Correct 2 ms 1292 KB Output is correct
9 Correct 2 ms 1292 KB Output is correct
10 Correct 2 ms 1292 KB Output is correct
11 Correct 2 ms 1292 KB Output is correct
12 Correct 2 ms 1292 KB Output is correct
13 Correct 2 ms 1304 KB Output is correct
14 Correct 3 ms 1308 KB Output is correct
15 Correct 3 ms 1820 KB Output is correct
16 Correct 2 ms 1820 KB Output is correct
17 Correct 2 ms 1820 KB Output is correct
18 Correct 2 ms 1820 KB Output is correct
19 Correct 2 ms 1820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2424 KB Output is correct
2 Correct 9 ms 2424 KB Output is correct
3 Correct 12 ms 3456 KB Output is correct
4 Correct 48 ms 16192 KB Output is correct
5 Correct 134 ms 43116 KB Output is correct
6 Correct 21 ms 43116 KB Output is correct
7 Correct 70 ms 43116 KB Output is correct
8 Correct 2 ms 43116 KB Output is correct
9 Correct 2 ms 43116 KB Output is correct
10 Correct 2 ms 43116 KB Output is correct
11 Correct 2 ms 43116 KB Output is correct
12 Correct 2 ms 43116 KB Output is correct
13 Correct 2 ms 43116 KB Output is correct
14 Correct 16 ms 43116 KB Output is correct
15 Correct 4 ms 43116 KB Output is correct
16 Correct 6 ms 43116 KB Output is correct
17 Correct 9 ms 43116 KB Output is correct
18 Correct 12 ms 43116 KB Output is correct
19 Correct 46 ms 43116 KB Output is correct
20 Correct 130 ms 46084 KB Output is correct
21 Correct 21 ms 46084 KB Output is correct
22 Correct 63 ms 46084 KB Output is correct
23 Correct 17 ms 46084 KB Output is correct
24 Correct 26 ms 46084 KB Output is correct
25 Correct 120 ms 49504 KB Output is correct
26 Correct 2 ms 49504 KB Output is correct
27 Correct 2 ms 49504 KB Output is correct
28 Correct 19 ms 49504 KB Output is correct
29 Correct 4 ms 49504 KB Output is correct
30 Correct 7 ms 49504 KB Output is correct
31 Correct 8 ms 49504 KB Output is correct
32 Correct 12 ms 49504 KB Output is correct
33 Correct 59 ms 49504 KB Output is correct
34 Correct 171 ms 51712 KB Output is correct
35 Correct 22 ms 51712 KB Output is correct
36 Correct 88 ms 51712 KB Output is correct
37 Correct 4 ms 51712 KB Output is correct
38 Correct 15 ms 51712 KB Output is correct
39 Correct 2 ms 51712 KB Output is correct
40 Correct 2 ms 51712 KB Output is correct
41 Correct 2 ms 51712 KB Output is correct
42 Correct 2 ms 51712 KB Output is correct