답안 #1043855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043855 2024-08-05T01:41:00 Z vjudge1 K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 4696 KB
#include <bits/stdc++.h>
#define file "main"
#define maxn (int) 1e5 + 5
#define pii pair<int, ll>
#define ll long long
#define gb(i, j) ((i >> j) & 1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r

#define f first
#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}

void iof() {
    if(fopen(file".inp", "r")) {
        freopen(file".inp", "r", stdin);
//        freopen(file".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

int n, k;
int a[maxn];
ll dp[105][maxn];
pii q[maxn];

void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; i ++) cin >> a[i];

    for(int i = 0; i <= k; i ++) for(int j = 0; j <= n; j ++)
        dp[i][j] = 1e18;
    dp[0][0] = 0;

    for(int _ = 1; _ <= k; _ ++) {
        int d = 1, c = 0;
        for(int i = 1; i <= n; i ++) {
            ll Mi = dp[_ - 1][i - 1];
            while(d <= c && a[q[c].f] < a[i]) {
                Mi = min(Mi, q[c].s);
                c --;
            }
            dp[_][i] = Mi + a[i];
            if(c) dp[_][i] = min(dp[_][i], dp[_ - 1][q[c].f]);
            q[++ c] = {i, Mi};
        }
    }
    cout << dp[k][n];
}

int main()
{
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --) {
        solve();
    }

    return 0;
}

Compilation message

blocks.cpp: In function 'void iof()':
blocks.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(file".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Incorrect 0 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -