Submission #1105084

#TimeUsernameProblemLanguageResultExecution timeMemory
1105084manhlinh1501K blocks (IZhO14_blocks)C++17
53 / 100
1012 ms43600 KiB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 1e5 + 5;
const int MAXK = 105;
const int LOGN = 19;

int N, K;
int a[MAXN];
int RMQ[MAXN][LOGN];

int get_max(int l, int r) {
    int k = __lg(r - l + 1);
    return max(RMQ[l][k], RMQ[r - (1 << k) + 1][k]);
}

namespace subtask {
    int dp[MAXN][MAXK];

    void solution() {
        memset(dp, 0x3f, sizeof dp);
        dp[0][0] = 0;
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= i; j++) {
                for(int z = 1; z <= K; z++) {
                    dp[i][z] = min(dp[i][z], dp[j - 1][z - 1] + get_max(j, i));
                }
            }
        }
        cout << dp[N][K] << "\n";
    }
}

signed main() {
#define task ""
    if(fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> K;
    for(int i = 1; i <= N; i++) cin >> a[i];
    for(int i = 1; i <= N; i++) RMQ[i][0] = a[i];
    for(int j = 1; j < LOGN; j++) {
        for(int i = 1; i + (1 << j) - 1 <= N; i++)
            RMQ[i][j] = max(RMQ[i][j - 1], RMQ[i + (1 << (j - 1))][j - 1]);
    }
    subtask::solution();
    return (0 ^ 0);
}

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...