답안 #854796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854796 2023-09-29T02:31:28 Z NeroZein K개의 묶음 (IZhO14_blocks) C++17
0 / 100
0 ms 348 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<long long> dp(n); 
  for (int i = 0, mx = 0; i < n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]); 
    dp[i] = mx; 
  }
  stack<pair<int, long long>> stk; 
  for (int j = 1; j < k; ++j) {
    stk.push({a[j - 1], dp[j - 1]});
    for (int i = j; i < n; ++i) {
      long long mn = LLONG_MAX; 
      while (!stk.empty() && stk.top().first <= a[i]) {
        mn = min(mn, stk.top().second); 
        stk.pop();
      }
      if (mn != LLONG_MAX && (stk.empty() || stk.top().first + stk.top().second > a[i] + mn)) {
        stk.push({a[i], mn}); 
      }
      long long val = stk.top().first + stk.top().second;
      if (stk.empty() || stk.top().first + stk.top().second > a[i] + dp[i]) {
        stk.push({a[i], dp[i]}); 
      }
      dp[i] = val; 
    }
  }
  cout << dp[n - 1] << '\n'; 
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -