답안 #13515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
13515 2015-02-22T14:03:25 Z tncks0121 K개의 묶음 (IZhO14_blocks) C++14
100 / 100
247 ms 43448 KB
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h> 
#include <time.h>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;

const int N_ = 100500;
const int K_ = 105;
int N, K, A[N_];

int tb[K_][N_];
stack<pii> stk;

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 1; i <= N; i++) scanf("%d", A + i);

	for (int i = 1; i <= N; i++) tb[0][i] = (int)2e8;
	for (int k = 1; k <= K; k++) {
		while(!stk.empty()) stk.pop();

		tb[k][k] = tb[k - 1][k - 1] + A[k];
		stk.push(pii(A[k], tb[k - 1][k - 1]));

		for (int i = k+1; i <= N; i++) {
			int c = tb[k - 1][i - 1];
			while (!stk.empty() && stk.top().first <= A[i]) {
				c = min(c, stk.top().second);
				stk.pop();
			}
			if (stk.empty() || stk.top().first + stk.top().second > A[i] + c)
				stk.push(pii(A[i], c));
			
			tb[k][i] = stk.top().first + stk.top().second;
		}
	}

	printf("%d\n", tb[K][N]);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 43192 KB Output is correct
2 Correct 0 ms 43192 KB Output is correct
3 Correct 0 ms 43192 KB Output is correct
4 Correct 0 ms 43192 KB Output is correct
5 Correct 0 ms 43192 KB Output is correct
6 Correct 0 ms 43192 KB Output is correct
7 Correct 0 ms 43192 KB Output is correct
8 Correct 0 ms 43192 KB Output is correct
9 Correct 0 ms 43192 KB Output is correct
10 Correct 0 ms 43192 KB Output is correct
11 Correct 0 ms 43192 KB Output is correct
12 Correct 0 ms 43192 KB Output is correct
13 Correct 0 ms 43192 KB Output is correct
14 Correct 0 ms 43192 KB Output is correct
15 Correct 0 ms 43192 KB Output is correct
16 Correct 0 ms 43192 KB Output is correct
17 Correct 0 ms 43192 KB Output is correct
18 Correct 0 ms 43192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 43192 KB Output is correct
2 Correct 0 ms 43192 KB Output is correct
3 Correct 0 ms 43192 KB Output is correct
4 Correct 0 ms 43192 KB Output is correct
5 Correct 0 ms 43192 KB Output is correct
6 Correct 0 ms 43192 KB Output is correct
7 Correct 0 ms 43192 KB Output is correct
8 Correct 0 ms 43192 KB Output is correct
9 Correct 0 ms 43192 KB Output is correct
10 Correct 0 ms 43192 KB Output is correct
11 Correct 0 ms 43192 KB Output is correct
12 Correct 0 ms 43192 KB Output is correct
13 Correct 0 ms 43192 KB Output is correct
14 Correct 0 ms 43192 KB Output is correct
15 Correct 0 ms 43192 KB Output is correct
16 Correct 0 ms 43192 KB Output is correct
17 Correct 0 ms 43192 KB Output is correct
18 Correct 0 ms 43192 KB Output is correct
19 Correct 0 ms 43192 KB Output is correct
20 Correct 0 ms 43192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 43192 KB Output is correct
2 Correct 0 ms 43192 KB Output is correct
3 Correct 0 ms 43192 KB Output is correct
4 Correct 0 ms 43192 KB Output is correct
5 Correct 0 ms 43192 KB Output is correct
6 Correct 0 ms 43192 KB Output is correct
7 Correct 0 ms 43192 KB Output is correct
8 Correct 0 ms 43192 KB Output is correct
9 Correct 0 ms 43192 KB Output is correct
10 Correct 0 ms 43192 KB Output is correct
11 Correct 0 ms 43192 KB Output is correct
12 Correct 0 ms 43192 KB Output is correct
13 Correct 0 ms 43192 KB Output is correct
14 Correct 0 ms 43192 KB Output is correct
15 Correct 0 ms 43192 KB Output is correct
16 Correct 0 ms 43192 KB Output is correct
17 Correct 0 ms 43192 KB Output is correct
18 Correct 0 ms 43192 KB Output is correct
19 Correct 0 ms 43192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 43192 KB Output is correct
2 Correct 7 ms 43192 KB Output is correct
3 Correct 13 ms 43192 KB Output is correct
4 Correct 54 ms 43192 KB Output is correct
5 Correct 135 ms 43192 KB Output is correct
6 Correct 23 ms 43192 KB Output is correct
7 Correct 70 ms 43192 KB Output is correct
8 Correct 0 ms 43192 KB Output is correct
9 Correct 0 ms 43192 KB Output is correct
10 Correct 0 ms 43192 KB Output is correct
11 Correct 0 ms 43192 KB Output is correct
12 Correct 0 ms 43192 KB Output is correct
13 Correct 0 ms 43192 KB Output is correct
14 Correct 9 ms 43192 KB Output is correct
15 Correct 0 ms 43192 KB Output is correct
16 Correct 3 ms 43192 KB Output is correct
17 Correct 0 ms 43192 KB Output is correct
18 Correct 12 ms 43192 KB Output is correct
19 Correct 48 ms 43192 KB Output is correct
20 Correct 108 ms 43192 KB Output is correct
21 Correct 18 ms 43192 KB Output is correct
22 Correct 56 ms 43192 KB Output is correct
23 Correct 0 ms 43192 KB Output is correct
24 Correct 21 ms 43192 KB Output is correct
25 Correct 115 ms 43192 KB Output is correct
26 Correct 0 ms 43192 KB Output is correct
27 Correct 0 ms 43192 KB Output is correct
28 Correct 24 ms 43192 KB Output is correct
29 Correct 0 ms 43192 KB Output is correct
30 Correct 9 ms 43192 KB Output is correct
31 Correct 0 ms 43192 KB Output is correct
32 Correct 12 ms 43320 KB Output is correct
33 Correct 82 ms 43320 KB Output is correct
34 Correct 247 ms 43448 KB Output is correct
35 Correct 7 ms 43448 KB Output is correct
36 Correct 121 ms 43448 KB Output is correct
37 Correct 0 ms 43192 KB Output is correct
38 Correct 7 ms 43192 KB Output is correct
39 Correct 0 ms 43192 KB Output is correct
40 Correct 0 ms 43192 KB Output is correct
41 Correct 0 ms 43192 KB Output is correct
42 Correct 0 ms 43192 KB Output is correct