답안 #5160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5160 2014-02-11T18:35:10 Z cki86201 K개의 묶음 (IZhO14_blocks) C++
100 / 100
220 ms 42464 KB
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> Pi;

int n, k, inp[100010];
int d[102][100010];

int main()
{
	scanf("%d%d",&n,&k);
	int i, j;
	for(i=1;i<=n;i++)scanf("%d",inp+i);
	for(i=1;i<=n;i++)d[1][i] = max(d[1][i-1], inp[i]);
	for(i=2;i<=k;i++){
		vector <Pi> v;
		for(j=i;j<=n;j++){
			int now = d[i-1][j-1];
			while(!v.empty() && v.back().X < inp[j])now = min(now, v.back().Y), v.pop_back();
			if(v.empty() || v.back().X + v.back().Y > inp[j] + now)v.push_back(Pi(inp[j],now));
			d[i][j] = v.back().X + v.back().Y;
		}
	}
	printf("%d",d[k][n]);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 41444 KB Output is correct
2 Correct 0 ms 41444 KB Output is correct
3 Correct 0 ms 41444 KB Output is correct
4 Correct 0 ms 41444 KB Output is correct
5 Correct 0 ms 41444 KB Output is correct
6 Correct 0 ms 41444 KB Output is correct
7 Correct 0 ms 41444 KB Output is correct
8 Correct 0 ms 41444 KB Output is correct
9 Correct 0 ms 41444 KB Output is correct
10 Correct 0 ms 41444 KB Output is correct
11 Correct 0 ms 41444 KB Output is correct
12 Correct 0 ms 41444 KB Output is correct
13 Correct 0 ms 41444 KB Output is correct
14 Correct 0 ms 41444 KB Output is correct
15 Correct 0 ms 41444 KB Output is correct
16 Correct 0 ms 41444 KB Output is correct
17 Correct 0 ms 41444 KB Output is correct
18 Correct 0 ms 41444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 41444 KB Output is correct
2 Correct 0 ms 41444 KB Output is correct
3 Correct 0 ms 41444 KB Output is correct
4 Correct 0 ms 41444 KB Output is correct
5 Correct 0 ms 41444 KB Output is correct
6 Correct 0 ms 41444 KB Output is correct
7 Correct 0 ms 41444 KB Output is correct
8 Correct 0 ms 41444 KB Output is correct
9 Correct 0 ms 41444 KB Output is correct
10 Correct 0 ms 41444 KB Output is correct
11 Correct 0 ms 41444 KB Output is correct
12 Correct 0 ms 41444 KB Output is correct
13 Correct 0 ms 41444 KB Output is correct
14 Correct 0 ms 41444 KB Output is correct
15 Correct 0 ms 41444 KB Output is correct
16 Correct 0 ms 41444 KB Output is correct
17 Correct 0 ms 41444 KB Output is correct
18 Correct 0 ms 41444 KB Output is correct
19 Correct 0 ms 41444 KB Output is correct
20 Correct 0 ms 41444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 41444 KB Output is correct
2 Correct 0 ms 41444 KB Output is correct
3 Correct 0 ms 41444 KB Output is correct
4 Correct 0 ms 41444 KB Output is correct
5 Correct 0 ms 41444 KB Output is correct
6 Correct 0 ms 41444 KB Output is correct
7 Correct 0 ms 41444 KB Output is correct
8 Correct 0 ms 41444 KB Output is correct
9 Correct 0 ms 41444 KB Output is correct
10 Correct 0 ms 41444 KB Output is correct
11 Correct 0 ms 41444 KB Output is correct
12 Correct 0 ms 41444 KB Output is correct
13 Correct 0 ms 41444 KB Output is correct
14 Correct 0 ms 41444 KB Output is correct
15 Correct 0 ms 41444 KB Output is correct
16 Correct 0 ms 41444 KB Output is correct
17 Correct 0 ms 41444 KB Output is correct
18 Correct 0 ms 41444 KB Output is correct
19 Correct 0 ms 41444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 41444 KB Output is correct
2 Correct 8 ms 41444 KB Output is correct
3 Correct 4 ms 41444 KB Output is correct
4 Correct 36 ms 41444 KB Output is correct
5 Correct 112 ms 41444 KB Output is correct
6 Correct 12 ms 41444 KB Output is correct
7 Correct 48 ms 41444 KB Output is correct
8 Correct 0 ms 41444 KB Output is correct
9 Correct 0 ms 41444 KB Output is correct
10 Correct 0 ms 41444 KB Output is correct
11 Correct 0 ms 41444 KB Output is correct
12 Correct 0 ms 41444 KB Output is correct
13 Correct 0 ms 41444 KB Output is correct
14 Correct 8 ms 41444 KB Output is correct
15 Correct 0 ms 41444 KB Output is correct
16 Correct 4 ms 41444 KB Output is correct
17 Correct 4 ms 41444 KB Output is correct
18 Correct 4 ms 41444 KB Output is correct
19 Correct 40 ms 41444 KB Output is correct
20 Correct 100 ms 41444 KB Output is correct
21 Correct 16 ms 41444 KB Output is correct
22 Correct 60 ms 41444 KB Output is correct
23 Correct 16 ms 41444 KB Output is correct
24 Correct 20 ms 41444 KB Output is correct
25 Correct 108 ms 41444 KB Output is correct
26 Correct 0 ms 41444 KB Output is correct
27 Correct 0 ms 41444 KB Output is correct
28 Correct 16 ms 41444 KB Output is correct
29 Correct 0 ms 41444 KB Output is correct
30 Correct 4 ms 41444 KB Output is correct
31 Correct 8 ms 41444 KB Output is correct
32 Correct 12 ms 41956 KB Output is correct
33 Correct 72 ms 41956 KB Output is correct
34 Correct 220 ms 42464 KB Output is correct
35 Correct 16 ms 42216 KB Output is correct
36 Correct 112 ms 42464 KB Output is correct
37 Correct 0 ms 41444 KB Output is correct
38 Correct 12 ms 41444 KB Output is correct
39 Correct 0 ms 41444 KB Output is correct
40 Correct 0 ms 41444 KB Output is correct
41 Correct 0 ms 41444 KB Output is correct
42 Correct 0 ms 41444 KB Output is correct