제출 #31755

#제출 시각아이디문제언어결과실행 시간메모리
31755aomeK개의 묶음 (IZhO14_blocks)C++14
0 / 100
3 ms3352 KiB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
const int N = 100005;
const int INF = 1e9;

int n, k, f[2][N], a[N];

int main() {
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) f[0][i] = INF;
    for (int i = 1; i <= k; ++i) {
        bool t = i & 1;
        stack<ii> st[2];
        f[t][0] = INF;
        for (int j = 1; j <= n; ++j) {
            int pos = j;
            int val = f[t ^ 1][j - 1];
            while (st[0].size() && a[st[0].top().first] <= a[j]) {
                pos = st[0].top().first;
                val = min(val, st[0].top().second);
                st[0].pop();
            }
            st[0].push(ii(j, val));
            while (st[1].size() && st[1].top().first >= pos) st[1].pop();
            if (!(st[1].size() && st[1].top().second <= val + a[j])) {
                st[1].push(ii(pos, val + a[j]));
            }
            f[t][j] = st[1].top().second;
            //cout << pos << ' ' << val << ' ' << f[t][j] << ' ' << j << '\n';
        }
    }
    cout << f[k & 1][n];
}

컴파일 시 표준 에러 (stderr) 메시지

blocks.cpp: In function 'int main()':
blocks.cpp:11:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("in.txt", "r", stdin);
                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...