답안 #470488

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470488 2021-09-04T05:32:31 Z lethinh05 K개의 묶음 (IZhO14_blocks) C++11
0 / 100
1 ms 204 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 ONLINE_JUDGE
        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;
        stack<ii> S;

        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:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
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]);
      |                  ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -