답안 #647761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647761 2022-10-04T02:58:11 Z x0r K개의 묶음 (IZhO14_blocks) C++17
100 / 100
240 ms 41980 KB
#pragma GCC optimize ("O2")
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define fi first 
#define se second
#define pll pair < ll, ll >
#define pii pair < int, int >
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

const string NAME = "";
const string NAME2 = "TEST";
const ld ESP = 1e-9;
const ll INF = 1e9 + 7;
const ll LINF = 1E18;
const ll nmax = 2e5;
const ll MOD = 1e9 + 7;
const ll base = 2309;

void fre() {
	string finp = NAME + ".inp";
	string fout = NAME + ".out";
	freopen(finp.c_str(), "r", stdin);
	freopen(fout.c_str(), "w", stdout);
}

int n, k, a[100003], dp[100003][103];

int main() {
	fast;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	memset(dp, 64, sizeof(dp));
	dp[1][1] = a[1];
	for (int i = 2; i <= n; i++) 
		dp[i][1] = max(dp[i - 1][1], a[i]);
	for (int j = 2; j <= k; j++) {
		stack < pii > st;
		for (int i = 1; i <= n; i++) {
			int val = dp[i - 1][j - 1], l;
			while (st.size() && a[i] >= a[st.top().se]) {
				val = min(val, st.top().fi);
				st.pop();
			}
			if (st.size()) l = st.top().se;
			else l = 0;
			st.push({val, i});
			dp[i][j] = min(dp[l][j], val + a[i]);
		}
	}
	cout << dp[n][k];
}

Compilation message

blocks.cpp: In function 'void fre()':
blocks.cpp:26:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  freopen(finp.c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:27:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  freopen(fout.c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 40532 KB Output is correct
2 Correct 19 ms 40560 KB Output is correct
3 Correct 18 ms 40528 KB Output is correct
4 Correct 17 ms 40532 KB Output is correct
5 Correct 17 ms 40524 KB Output is correct
6 Correct 18 ms 40524 KB Output is correct
7 Correct 18 ms 40532 KB Output is correct
8 Correct 19 ms 40572 KB Output is correct
9 Correct 22 ms 40520 KB Output is correct
10 Correct 19 ms 40596 KB Output is correct
11 Correct 18 ms 40580 KB Output is correct
12 Correct 23 ms 40616 KB Output is correct
13 Correct 17 ms 40532 KB Output is correct
14 Correct 18 ms 40532 KB Output is correct
15 Correct 17 ms 40560 KB Output is correct
16 Correct 19 ms 40592 KB Output is correct
17 Correct 22 ms 40516 KB Output is correct
18 Correct 19 ms 40524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 40568 KB Output is correct
2 Correct 19 ms 40552 KB Output is correct
3 Correct 18 ms 40548 KB Output is correct
4 Correct 17 ms 40532 KB Output is correct
5 Correct 18 ms 40576 KB Output is correct
6 Correct 19 ms 40532 KB Output is correct
7 Correct 19 ms 40524 KB Output is correct
8 Correct 18 ms 40552 KB Output is correct
9 Correct 16 ms 40524 KB Output is correct
10 Correct 17 ms 40580 KB Output is correct
11 Correct 16 ms 40644 KB Output is correct
12 Correct 18 ms 40524 KB Output is correct
13 Correct 20 ms 40528 KB Output is correct
14 Correct 19 ms 40564 KB Output is correct
15 Correct 18 ms 40532 KB Output is correct
16 Correct 19 ms 40668 KB Output is correct
17 Correct 18 ms 40532 KB Output is correct
18 Correct 16 ms 40528 KB Output is correct
19 Correct 16 ms 40524 KB Output is correct
20 Correct 17 ms 40652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 40532 KB Output is correct
2 Correct 19 ms 40560 KB Output is correct
3 Correct 18 ms 40528 KB Output is correct
4 Correct 17 ms 40532 KB Output is correct
5 Correct 17 ms 40524 KB Output is correct
6 Correct 18 ms 40524 KB Output is correct
7 Correct 18 ms 40532 KB Output is correct
8 Correct 19 ms 40572 KB Output is correct
9 Correct 22 ms 40520 KB Output is correct
10 Correct 19 ms 40596 KB Output is correct
11 Correct 18 ms 40580 KB Output is correct
12 Correct 23 ms 40616 KB Output is correct
13 Correct 17 ms 40532 KB Output is correct
14 Correct 18 ms 40532 KB Output is correct
15 Correct 17 ms 40560 KB Output is correct
16 Correct 19 ms 40592 KB Output is correct
17 Correct 22 ms 40516 KB Output is correct
18 Correct 19 ms 40524 KB Output is correct
19 Correct 18 ms 40568 KB Output is correct
20 Correct 19 ms 40552 KB Output is correct
21 Correct 18 ms 40548 KB Output is correct
22 Correct 17 ms 40532 KB Output is correct
23 Correct 18 ms 40576 KB Output is correct
24 Correct 19 ms 40532 KB Output is correct
25 Correct 19 ms 40524 KB Output is correct
26 Correct 18 ms 40552 KB Output is correct
27 Correct 16 ms 40524 KB Output is correct
28 Correct 17 ms 40580 KB Output is correct
29 Correct 16 ms 40644 KB Output is correct
30 Correct 18 ms 40524 KB Output is correct
31 Correct 20 ms 40528 KB Output is correct
32 Correct 19 ms 40564 KB Output is correct
33 Correct 18 ms 40532 KB Output is correct
34 Correct 19 ms 40668 KB Output is correct
35 Correct 18 ms 40532 KB Output is correct
36 Correct 16 ms 40528 KB Output is correct
37 Correct 16 ms 40524 KB Output is correct
38 Correct 17 ms 40652 KB Output is correct
39 Correct 17 ms 40512 KB Output is correct
40 Correct 16 ms 40532 KB Output is correct
41 Correct 18 ms 40548 KB Output is correct
42 Correct 18 ms 40532 KB Output is correct
43 Correct 23 ms 40532 KB Output is correct
44 Correct 17 ms 40512 KB Output is correct
45 Correct 18 ms 40608 KB Output is correct
46 Correct 17 ms 40560 KB Output is correct
47 Correct 18 ms 40528 KB Output is correct
48 Correct 17 ms 40524 KB Output is correct
49 Correct 18 ms 40524 KB Output is correct
50 Correct 18 ms 40644 KB Output is correct
51 Correct 21 ms 40524 KB Output is correct
52 Correct 19 ms 40644 KB Output is correct
53 Correct 18 ms 40520 KB Output is correct
54 Correct 20 ms 40536 KB Output is correct
55 Correct 17 ms 40624 KB Output is correct
56 Correct 17 ms 40532 KB Output is correct
57 Correct 23 ms 40524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 40532 KB Output is correct
2 Correct 19 ms 40560 KB Output is correct
3 Correct 18 ms 40528 KB Output is correct
4 Correct 17 ms 40532 KB Output is correct
5 Correct 17 ms 40524 KB Output is correct
6 Correct 18 ms 40524 KB Output is correct
7 Correct 18 ms 40532 KB Output is correct
8 Correct 19 ms 40572 KB Output is correct
9 Correct 22 ms 40520 KB Output is correct
10 Correct 19 ms 40596 KB Output is correct
11 Correct 18 ms 40580 KB Output is correct
12 Correct 23 ms 40616 KB Output is correct
13 Correct 17 ms 40532 KB Output is correct
14 Correct 18 ms 40532 KB Output is correct
15 Correct 17 ms 40560 KB Output is correct
16 Correct 19 ms 40592 KB Output is correct
17 Correct 22 ms 40516 KB Output is correct
18 Correct 19 ms 40524 KB Output is correct
19 Correct 18 ms 40568 KB Output is correct
20 Correct 19 ms 40552 KB Output is correct
21 Correct 18 ms 40548 KB Output is correct
22 Correct 17 ms 40532 KB Output is correct
23 Correct 18 ms 40576 KB Output is correct
24 Correct 19 ms 40532 KB Output is correct
25 Correct 19 ms 40524 KB Output is correct
26 Correct 18 ms 40552 KB Output is correct
27 Correct 16 ms 40524 KB Output is correct
28 Correct 17 ms 40580 KB Output is correct
29 Correct 16 ms 40644 KB Output is correct
30 Correct 18 ms 40524 KB Output is correct
31 Correct 20 ms 40528 KB Output is correct
32 Correct 19 ms 40564 KB Output is correct
33 Correct 18 ms 40532 KB Output is correct
34 Correct 19 ms 40668 KB Output is correct
35 Correct 18 ms 40532 KB Output is correct
36 Correct 16 ms 40528 KB Output is correct
37 Correct 16 ms 40524 KB Output is correct
38 Correct 17 ms 40652 KB Output is correct
39 Correct 17 ms 40512 KB Output is correct
40 Correct 16 ms 40532 KB Output is correct
41 Correct 18 ms 40548 KB Output is correct
42 Correct 18 ms 40532 KB Output is correct
43 Correct 23 ms 40532 KB Output is correct
44 Correct 17 ms 40512 KB Output is correct
45 Correct 18 ms 40608 KB Output is correct
46 Correct 17 ms 40560 KB Output is correct
47 Correct 18 ms 40528 KB Output is correct
48 Correct 17 ms 40524 KB Output is correct
49 Correct 18 ms 40524 KB Output is correct
50 Correct 18 ms 40644 KB Output is correct
51 Correct 21 ms 40524 KB Output is correct
52 Correct 19 ms 40644 KB Output is correct
53 Correct 18 ms 40520 KB Output is correct
54 Correct 20 ms 40536 KB Output is correct
55 Correct 17 ms 40624 KB Output is correct
56 Correct 17 ms 40532 KB Output is correct
57 Correct 23 ms 40524 KB Output is correct
58 Correct 23 ms 40748 KB Output is correct
59 Correct 26 ms 40988 KB Output is correct
60 Correct 28 ms 41028 KB Output is correct
61 Correct 66 ms 41096 KB Output is correct
62 Correct 207 ms 41672 KB Output is correct
63 Correct 38 ms 41628 KB Output is correct
64 Correct 109 ms 41692 KB Output is correct
65 Correct 19 ms 40524 KB Output is correct
66 Correct 18 ms 40532 KB Output is correct
67 Correct 17 ms 40532 KB Output is correct
68 Correct 17 ms 40532 KB Output is correct
69 Correct 17 ms 40580 KB Output is correct
70 Correct 17 ms 40592 KB Output is correct
71 Correct 41 ms 40656 KB Output is correct
72 Correct 19 ms 40656 KB Output is correct
73 Correct 21 ms 40660 KB Output is correct
74 Correct 20 ms 41060 KB Output is correct
75 Correct 33 ms 41004 KB Output is correct
76 Correct 108 ms 41096 KB Output is correct
77 Correct 229 ms 41680 KB Output is correct
78 Correct 34 ms 41720 KB Output is correct
79 Correct 120 ms 41680 KB Output is correct
80 Correct 26 ms 41684 KB Output is correct
81 Correct 46 ms 41604 KB Output is correct
82 Correct 240 ms 41692 KB Output is correct
83 Correct 18 ms 40660 KB Output is correct
84 Correct 20 ms 40588 KB Output is correct
85 Correct 33 ms 40724 KB Output is correct
86 Correct 19 ms 40672 KB Output is correct
87 Correct 22 ms 40688 KB Output is correct
88 Correct 24 ms 41016 KB Output is correct
89 Correct 27 ms 41248 KB Output is correct
90 Correct 75 ms 41176 KB Output is correct
91 Correct 218 ms 41976 KB Output is correct
92 Correct 31 ms 41932 KB Output is correct
93 Correct 140 ms 41980 KB Output is correct
94 Correct 20 ms 40656 KB Output is correct
95 Correct 30 ms 40732 KB Output is correct
96 Correct 18 ms 40532 KB Output is correct
97 Correct 17 ms 40560 KB Output is correct
98 Correct 19 ms 40580 KB Output is correct
99 Correct 18 ms 40532 KB Output is correct