답안 #1039072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039072 2024-07-30T12:27:46 Z ttviet2805 K개의 묶음 (IZhO14_blocks) C++14
100 / 100
241 ms 82024 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define II pair <int, int>
#define fi first
#define se second
#define all(S) S.begin(), S.end()

const int INF = 1e15;
const int N = 1e5 + 5;
int n, a[N], K;

void in() {
	cin >> n >> K;	
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector <vector <int>> f(K + 1, vector <int> (n + 5, INF));
	f[0][0] = 0;
	for(int X = 1; X <= K; X++) {
		stack <II> st;
		st.push({X - 1, f[X - 1][X - 1]});
		for(int i = X; i <= n; i++) {
			int curMin = INF;
			while(!st.empty() && a[i] >= a[st.top().fi]) {
				curMin = min(curMin, st.top().se);
				st.pop();
			}
			int res = curMin;
			if(!st.empty()) {
				res = min(curMin, f[X - 1][st.top().fi]);
				f[X][i] = f[X][st.top().fi];
			}
			f[X][i] = min(f[X][i], res + a[i]);
			curMin = min(curMin, f[X - 1][i]);
			st.push({i, curMin});
		}
	}
	// for(int X = 1; X <= K; X++) {
	// 	for(int i = 1; i <= n; i++) {
	// 		cout << "#: " << X << ' ' << i << "\t" << f[X][i] << endl;
	// 	}
	// }
	cout << f[K][n] << '\n';
}

void process() {
	
}

int32_t main() {
	if(fopen("trash.inp", "r"))
		freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T = 1;
	while(T--) {
		in();
		process();
	}
}

Compilation message

blocks.cpp: In function 'int32_t main()':
blocks.cpp:54:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:54:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 464 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 352 KB Output is correct
43 Correct 0 ms 352 KB Output is correct
44 Correct 0 ms 352 KB Output is correct
45 Correct 0 ms 352 KB Output is correct
46 Correct 0 ms 352 KB Output is correct
47 Correct 0 ms 352 KB Output is correct
48 Correct 0 ms 352 KB Output is correct
49 Correct 0 ms 352 KB Output is correct
50 Correct 0 ms 360 KB Output is correct
51 Correct 0 ms 360 KB Output is correct
52 Correct 0 ms 360 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 468 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 464 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 352 KB Output is correct
43 Correct 0 ms 352 KB Output is correct
44 Correct 0 ms 352 KB Output is correct
45 Correct 0 ms 352 KB Output is correct
46 Correct 0 ms 352 KB Output is correct
47 Correct 0 ms 352 KB Output is correct
48 Correct 0 ms 352 KB Output is correct
49 Correct 0 ms 352 KB Output is correct
50 Correct 0 ms 360 KB Output is correct
51 Correct 0 ms 360 KB Output is correct
52 Correct 0 ms 360 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 468 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 6 ms 2652 KB Output is correct
59 Correct 4 ms 2132 KB Output is correct
60 Correct 9 ms 4132 KB Output is correct
61 Correct 73 ms 28248 KB Output is correct
62 Correct 216 ms 82000 KB Output is correct
63 Correct 14 ms 5720 KB Output is correct
64 Correct 103 ms 38740 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 1 ms 344 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 22 ms 8540 KB Output is correct
72 Correct 1 ms 860 KB Output is correct
73 Correct 6 ms 2732 KB Output is correct
74 Correct 4 ms 2136 KB Output is correct
75 Correct 10 ms 4188 KB Output is correct
76 Correct 81 ms 28248 KB Output is correct
77 Correct 241 ms 82000 KB Output is correct
78 Correct 13 ms 5720 KB Output is correct
79 Correct 112 ms 38748 KB Output is correct
80 Correct 9 ms 4184 KB Output is correct
81 Correct 32 ms 11312 KB Output is correct
82 Correct 238 ms 82004 KB Output is correct
83 Correct 1 ms 344 KB Output is correct
84 Correct 1 ms 348 KB Output is correct
85 Correct 23 ms 8452 KB Output is correct
86 Correct 2 ms 856 KB Output is correct
87 Correct 6 ms 2732 KB Output is correct
88 Correct 4 ms 2136 KB Output is correct
89 Correct 10 ms 4184 KB Output is correct
90 Correct 78 ms 28248 KB Output is correct
91 Correct 233 ms 82024 KB Output is correct
92 Correct 13 ms 5720 KB Output is correct
93 Correct 114 ms 38712 KB Output is correct
94 Correct 1 ms 692 KB Output is correct
95 Correct 20 ms 8536 KB Output is correct
96 Correct 1 ms 344 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct