답안 #1043859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043859 2024-08-05T01:50:54 Z vjudge1 K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>
#define file "main"
#define maxn (int) 1e5 + 5
#define pii pair<int, int>
#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];
int 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 = 1; j <= n; j ++)
        dp[i][j] = 1e9;
    dp[0][0] = 0;

    for(int _ = 1; _ <= k; _ ++) {
        int d = 1, c = 0;
        for(int i = 1; i <= n; i ++) {
            int Mi = dp[_ - 1][i - 1];
            while(d <= c && a[i] >= a[q[c].f]) {
                Mi = min(Mi, q[c].s);
                c --;
            }
            dp[_][i] = Mi + a[i];
            if(c) dp[_][i] = min(dp[_][i], dp[_][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 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -