답안 #1077201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077201 2024-08-27T02:53:51 Z Wjsc K개의 묶음 (IZhO14_blocks) C++14
0 / 100
42 ms 82552 KB
#include<bits/stdc++.h>

using namespace std;

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

const int N = 1e5 + 5,
          M = 1e2 + 5,
          INF = 1e18;

int n, k;
int a[N];
int f[N][M];

signed main() {
  cin.tie(0)->sync_with_stdio(0);

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

  cin >> n >> k;

  for(int i = 1; i <= n; ++i) {
    cin >> a[i];
    if(i == 1) f[i][1] = a[i];
    else f[i][1] = max(f[i - 1][1], a[i]);
  }

  for(int j = 2; j <= k; ++j) {
    stack<pi> st;

    int c = INF;

    for(int i = 1; i <= n; ++i) {
      while(st.size() && a[st.top().fi] <= a[i]) {
        f[i][j] = min(f[i][j], f[st.top().fi][j - 1] + a[i]);
        f[i][j] = min(f[i][j], st.top().se + a[i]);
        c = min(c, st.top().se);
        c = min(c, f[st.top().fi][j - 1]);
        st.pop();
      }

      if(st.size()) {
        f[i][j] = min(f[i][j], f[st.top().fi][j]);
        f[i][j] = min(f[i][j], f[st.top().fi][j - 1] + a[i]);
      }
      st.push({i, c});
    }
  }

  cout << f[n][k];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 82524 KB Output is correct
2 Correct 39 ms 82404 KB Output is correct
3 Correct 35 ms 82512 KB Output is correct
4 Correct 41 ms 82516 KB Output is correct
5 Correct 35 ms 82512 KB Output is correct
6 Correct 36 ms 82516 KB Output is correct
7 Correct 42 ms 82516 KB Output is correct
8 Correct 35 ms 82552 KB Output is correct
9 Correct 35 ms 82516 KB Output is correct
10 Incorrect 38 ms 82516 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 82520 KB Output is correct
2 Correct 39 ms 82516 KB Output is correct
3 Correct 36 ms 82516 KB Output is correct
4 Correct 36 ms 82524 KB Output is correct
5 Correct 35 ms 82516 KB Output is correct
6 Correct 35 ms 82524 KB Output is correct
7 Correct 36 ms 82512 KB Output is correct
8 Correct 42 ms 82516 KB Output is correct
9 Correct 36 ms 82512 KB Output is correct
10 Incorrect 36 ms 82516 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 82524 KB Output is correct
2 Correct 39 ms 82404 KB Output is correct
3 Correct 35 ms 82512 KB Output is correct
4 Correct 41 ms 82516 KB Output is correct
5 Correct 35 ms 82512 KB Output is correct
6 Correct 36 ms 82516 KB Output is correct
7 Correct 42 ms 82516 KB Output is correct
8 Correct 35 ms 82552 KB Output is correct
9 Correct 35 ms 82516 KB Output is correct
10 Incorrect 38 ms 82516 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 82524 KB Output is correct
2 Correct 39 ms 82404 KB Output is correct
3 Correct 35 ms 82512 KB Output is correct
4 Correct 41 ms 82516 KB Output is correct
5 Correct 35 ms 82512 KB Output is correct
6 Correct 36 ms 82516 KB Output is correct
7 Correct 42 ms 82516 KB Output is correct
8 Correct 35 ms 82552 KB Output is correct
9 Correct 35 ms 82516 KB Output is correct
10 Incorrect 38 ms 82516 KB Output isn't correct
11 Halted 0 ms 0 KB -