Submission #872716

# Submission time Handle Problem Language Result Execution time Memory
872716 2023-11-13T15:31:43 Z vjudge1 K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>

#define FOR(i, l, r) for(int i = (l); i <= (r); i ++)
#define ll long long
#define MASK(j)  (1LL << (j))
#define int ll

using namespace std;

int f[100001][101];
int a[200000];

signed main() {
    if(fopen("MAXK.inp", "r")) {
        freopen("MAXK.inp", "r", stdin);
        freopen("MAXK.out", "w", stdout);
    }

    if(fopen("a.inp", "r")) {
        freopen("a.inp", "r", stdin);
        freopen("a.out", "w", stdout);
    }

    int n, k;
    cin >> n >> k;

    FOR(i, 1, n) cin >> a[i];
    ll mx = 0;
    FOR(i, 1, n) mx = max(mx, a[i]), f[i][1] = mx;

    FOR(j, 2, k){
        stack <pair <int,int>> q;
        ll minF = 1e18;
        FOR(i, 1, n){
            while(q.size() && a[q.top().first] <= a[i]){
                minF = min(minF, q.top().second);
                q.pop();
            }


            f[i][j] = minF + a[i];
            q.push({i, f[i][j - 1]});
        }
    }

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

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen("MAXK.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen("MAXK.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("a.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
blocks.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("a.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 1 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Correct 0 ms 2396 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 1 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 1 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -