답안 #1077837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077837 2024-08-27T09:33:05 Z duyhoanho K개의 묶음 (IZhO14_blocks) C++14
100 / 100
200 ms 84388 KB
#include <bits/stdc++.h>
#define task ""

using namespace std;
const int N = 1e5 + 5,
          M = 105;
long long n, a[N], dp[N][M], k;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  if (fopen ("task.inp", "r")) {
    freopen ("task.inp", "r", stdin);
    freopen ("task.out", "w", stdout);
  }

  if (fopen (task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  cin >> n >> k;
  long long mx = -1e9;
  memset(dp, 126, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mx = max (mx, a[i]);
    dp[i][1] = mx;
  }

  for (int j = 2; j <= k; j++) {
    stack <long long> st;
    for (int i = 1; i <= n; i++) {
      while (!st.empty() and a[st.top()] <= a[i]) {
        dp[i][j] = min (dp[i][j], dp[st.top()][j - 1] + a[i]);
        dp[i][j] = min (dp[i][j], dp[st.top()][j] - a[st.top()] + a[i]);
        st.pop();
      }

      if (!st.empty()) {
        dp[i][j] = min(dp[i][j], dp[st.top()][j - 1] + a[i]);
        dp[i][j] = min(dp[i][j], dp[st.top()][j]);
        dp[i][j] = min(dp[i][j], dp[st.top() - 1][j - 1] + a[st.top()]);
      }

      st.push(i);
    }
  }
  cout << dp[n][k];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:14:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen ("task.inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:15:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen ("task.out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:19:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:20:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 82520 KB Output is correct
2 Correct 39 ms 82524 KB Output is correct
3 Correct 41 ms 82640 KB Output is correct
4 Correct 40 ms 82428 KB Output is correct
5 Correct 41 ms 82420 KB Output is correct
6 Correct 38 ms 82516 KB Output is correct
7 Correct 42 ms 82508 KB Output is correct
8 Correct 39 ms 82520 KB Output is correct
9 Correct 40 ms 82512 KB Output is correct
10 Correct 39 ms 82544 KB Output is correct
11 Correct 40 ms 82524 KB Output is correct
12 Correct 37 ms 82544 KB Output is correct
13 Correct 50 ms 82592 KB Output is correct
14 Correct 38 ms 82516 KB Output is correct
15 Correct 38 ms 82524 KB Output is correct
16 Correct 48 ms 82512 KB Output is correct
17 Correct 35 ms 82520 KB Output is correct
18 Correct 37 ms 82596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 82512 KB Output is correct
2 Correct 36 ms 82600 KB Output is correct
3 Correct 35 ms 82512 KB Output is correct
4 Correct 36 ms 82516 KB Output is correct
5 Correct 36 ms 82516 KB Output is correct
6 Correct 39 ms 82516 KB Output is correct
7 Correct 37 ms 82480 KB Output is correct
8 Correct 37 ms 82512 KB Output is correct
9 Correct 38 ms 82512 KB Output is correct
10 Correct 36 ms 82576 KB Output is correct
11 Correct 37 ms 82516 KB Output is correct
12 Correct 37 ms 82516 KB Output is correct
13 Correct 41 ms 82516 KB Output is correct
14 Correct 35 ms 82516 KB Output is correct
15 Correct 46 ms 82520 KB Output is correct
16 Correct 50 ms 82512 KB Output is correct
17 Correct 38 ms 82512 KB Output is correct
18 Correct 38 ms 82524 KB Output is correct
19 Correct 38 ms 82492 KB Output is correct
20 Correct 39 ms 82628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 82520 KB Output is correct
2 Correct 39 ms 82524 KB Output is correct
3 Correct 41 ms 82640 KB Output is correct
4 Correct 40 ms 82428 KB Output is correct
5 Correct 41 ms 82420 KB Output is correct
6 Correct 38 ms 82516 KB Output is correct
7 Correct 42 ms 82508 KB Output is correct
8 Correct 39 ms 82520 KB Output is correct
9 Correct 40 ms 82512 KB Output is correct
10 Correct 39 ms 82544 KB Output is correct
11 Correct 40 ms 82524 KB Output is correct
12 Correct 37 ms 82544 KB Output is correct
13 Correct 50 ms 82592 KB Output is correct
14 Correct 38 ms 82516 KB Output is correct
15 Correct 38 ms 82524 KB Output is correct
16 Correct 48 ms 82512 KB Output is correct
17 Correct 35 ms 82520 KB Output is correct
18 Correct 37 ms 82596 KB Output is correct
19 Correct 38 ms 82512 KB Output is correct
20 Correct 36 ms 82600 KB Output is correct
21 Correct 35 ms 82512 KB Output is correct
22 Correct 36 ms 82516 KB Output is correct
23 Correct 36 ms 82516 KB Output is correct
24 Correct 39 ms 82516 KB Output is correct
25 Correct 37 ms 82480 KB Output is correct
26 Correct 37 ms 82512 KB Output is correct
27 Correct 38 ms 82512 KB Output is correct
28 Correct 36 ms 82576 KB Output is correct
29 Correct 37 ms 82516 KB Output is correct
30 Correct 37 ms 82516 KB Output is correct
31 Correct 41 ms 82516 KB Output is correct
32 Correct 35 ms 82516 KB Output is correct
33 Correct 46 ms 82520 KB Output is correct
34 Correct 50 ms 82512 KB Output is correct
35 Correct 38 ms 82512 KB Output is correct
36 Correct 38 ms 82524 KB Output is correct
37 Correct 38 ms 82492 KB Output is correct
38 Correct 39 ms 82628 KB Output is correct
39 Correct 38 ms 82516 KB Output is correct
40 Correct 33 ms 82524 KB Output is correct
41 Correct 38 ms 82428 KB Output is correct
42 Correct 40 ms 82580 KB Output is correct
43 Correct 39 ms 82536 KB Output is correct
44 Correct 34 ms 82516 KB Output is correct
45 Correct 36 ms 82524 KB Output is correct
46 Correct 33 ms 82628 KB Output is correct
47 Correct 38 ms 82512 KB Output is correct
48 Correct 42 ms 82512 KB Output is correct
49 Correct 39 ms 82524 KB Output is correct
50 Correct 37 ms 82516 KB Output is correct
51 Correct 36 ms 82552 KB Output is correct
52 Correct 35 ms 82516 KB Output is correct
53 Correct 48 ms 82512 KB Output is correct
54 Correct 33 ms 82516 KB Output is correct
55 Correct 34 ms 82552 KB Output is correct
56 Correct 49 ms 82516 KB Output is correct
57 Correct 40 ms 82512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 82520 KB Output is correct
2 Correct 39 ms 82524 KB Output is correct
3 Correct 41 ms 82640 KB Output is correct
4 Correct 40 ms 82428 KB Output is correct
5 Correct 41 ms 82420 KB Output is correct
6 Correct 38 ms 82516 KB Output is correct
7 Correct 42 ms 82508 KB Output is correct
8 Correct 39 ms 82520 KB Output is correct
9 Correct 40 ms 82512 KB Output is correct
10 Correct 39 ms 82544 KB Output is correct
11 Correct 40 ms 82524 KB Output is correct
12 Correct 37 ms 82544 KB Output is correct
13 Correct 50 ms 82592 KB Output is correct
14 Correct 38 ms 82516 KB Output is correct
15 Correct 38 ms 82524 KB Output is correct
16 Correct 48 ms 82512 KB Output is correct
17 Correct 35 ms 82520 KB Output is correct
18 Correct 37 ms 82596 KB Output is correct
19 Correct 38 ms 82512 KB Output is correct
20 Correct 36 ms 82600 KB Output is correct
21 Correct 35 ms 82512 KB Output is correct
22 Correct 36 ms 82516 KB Output is correct
23 Correct 36 ms 82516 KB Output is correct
24 Correct 39 ms 82516 KB Output is correct
25 Correct 37 ms 82480 KB Output is correct
26 Correct 37 ms 82512 KB Output is correct
27 Correct 38 ms 82512 KB Output is correct
28 Correct 36 ms 82576 KB Output is correct
29 Correct 37 ms 82516 KB Output is correct
30 Correct 37 ms 82516 KB Output is correct
31 Correct 41 ms 82516 KB Output is correct
32 Correct 35 ms 82516 KB Output is correct
33 Correct 46 ms 82520 KB Output is correct
34 Correct 50 ms 82512 KB Output is correct
35 Correct 38 ms 82512 KB Output is correct
36 Correct 38 ms 82524 KB Output is correct
37 Correct 38 ms 82492 KB Output is correct
38 Correct 39 ms 82628 KB Output is correct
39 Correct 38 ms 82516 KB Output is correct
40 Correct 33 ms 82524 KB Output is correct
41 Correct 38 ms 82428 KB Output is correct
42 Correct 40 ms 82580 KB Output is correct
43 Correct 39 ms 82536 KB Output is correct
44 Correct 34 ms 82516 KB Output is correct
45 Correct 36 ms 82524 KB Output is correct
46 Correct 33 ms 82628 KB Output is correct
47 Correct 38 ms 82512 KB Output is correct
48 Correct 42 ms 82512 KB Output is correct
49 Correct 39 ms 82524 KB Output is correct
50 Correct 37 ms 82516 KB Output is correct
51 Correct 36 ms 82552 KB Output is correct
52 Correct 35 ms 82516 KB Output is correct
53 Correct 48 ms 82512 KB Output is correct
54 Correct 33 ms 82516 KB Output is correct
55 Correct 34 ms 82552 KB Output is correct
56 Correct 49 ms 82516 KB Output is correct
57 Correct 40 ms 82512 KB Output is correct
58 Correct 37 ms 82768 KB Output is correct
59 Correct 35 ms 83176 KB Output is correct
60 Correct 43 ms 83068 KB Output is correct
61 Correct 75 ms 83284 KB Output is correct
62 Correct 162 ms 84096 KB Output is correct
63 Correct 61 ms 84048 KB Output is correct
64 Correct 90 ms 83904 KB Output is correct
65 Correct 35 ms 82516 KB Output is correct
66 Correct 41 ms 82516 KB Output is correct
67 Correct 42 ms 82524 KB Output is correct
68 Correct 35 ms 82520 KB Output is correct
69 Correct 34 ms 82420 KB Output is correct
70 Correct 34 ms 82516 KB Output is correct
71 Correct 65 ms 82768 KB Output is correct
72 Correct 39 ms 82780 KB Output is correct
73 Correct 40 ms 82524 KB Output is correct
74 Correct 52 ms 83280 KB Output is correct
75 Correct 44 ms 83280 KB Output is correct
76 Correct 89 ms 83280 KB Output is correct
77 Correct 196 ms 84048 KB Output is correct
78 Correct 50 ms 83960 KB Output is correct
79 Correct 120 ms 84092 KB Output is correct
80 Correct 43 ms 84052 KB Output is correct
81 Correct 59 ms 84048 KB Output is correct
82 Correct 200 ms 83904 KB Output is correct
83 Correct 38 ms 82584 KB Output is correct
84 Correct 35 ms 82408 KB Output is correct
85 Correct 53 ms 82768 KB Output is correct
86 Correct 39 ms 82632 KB Output is correct
87 Correct 42 ms 82584 KB Output is correct
88 Correct 41 ms 83064 KB Output is correct
89 Correct 40 ms 83200 KB Output is correct
90 Correct 81 ms 83420 KB Output is correct
91 Correct 169 ms 84388 KB Output is correct
92 Correct 46 ms 84320 KB Output is correct
93 Correct 99 ms 84388 KB Output is correct
94 Correct 35 ms 82768 KB Output is correct
95 Correct 58 ms 82616 KB Output is correct
96 Correct 37 ms 82440 KB Output is correct
97 Correct 46 ms 82464 KB Output is correct
98 Correct 38 ms 82516 KB Output is correct
99 Correct 36 ms 82396 KB Output is correct