Submission #470493

# Submission time Handle Problem Language Result Execution time Memory
470493 2021-09-04T05:45:33 Z lethinh05 K blocks (IZhO14_blocks) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

#define oo 1000000007
#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mp make_pair
#define vi vector<int>
#define vii vector<ii>
#define sz(a) (int)(a.size())
#define pb push_back
#define fto(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define fdto(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define sci(x) scanf("%d", &x)
#define scii(x, y) scanf("%d %d", &x, &y)
#define bug(x) "["#x" = "<<(x)<<"] "
#define maxN 100005

using namespace std;

int n, k, a[maxN], f[105][maxN];

int main() {
    #ifndef EVAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    scii(n, k);
    fto(i, 1, n) sci(a[i]);

    fto(i, 1, n) f[1][i] = max(f[1][i-1], a[i]);
    fto(i, 2, k) {
        f[i][0] = oo;

        fto(j, i, n) {
            int mn = f[i-1][j-1];

            while (!S.empty() && a[S.top().ss] <= a[j]) {
                mn = min(mn, S.top().ff);
                S.pop();
            }

            f[i][j] = min(f[i][S.empty() ? 0 : S.top().ss], mn + a[j]);
            S.push(mp(mn, j));
        }
    }

    printf("%d\n", f[k][n]);
    return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:41:21: error: 'S' was not declared in this scope
   41 |             while (!S.empty() && a[S.top().ss] <= a[j]) {
      |                     ^
blocks.cpp:46:32: error: 'S' was not declared in this scope
   46 |             f[i][j] = min(f[i][S.empty() ? 0 : S.top().ss], mn + a[j]);
      |                                ^
blocks.cpp:17:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define scii(x, y) scanf("%d %d", &x, &y)
      |                    ~~~~~^~~~~~~~~~~~~~~~~
blocks.cpp:31:5: note: in expansion of macro 'scii'
   31 |     scii(n, k);
      |     ^~~~
blocks.cpp:16:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define sci(x) scanf("%d", &x)
      |                ~~~~~^~~~~~~~~~
blocks.cpp:32:18: note: in expansion of macro 'sci'
   32 |     fto(i, 1, n) sci(a[i]);
      |                  ^~~