제출 #684836

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

const int mod = 1e9 + 7;
const auto seed = chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 ran(seed);

#define ll long long
#define int long long
#define se second
#define fi first
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define REP(i, a, b) for (int i = (a), _b = (b); i < _b; i++)
#define FOD(i,r,l) for(int i=r; i>=l; i--)
#define ed <<'\n';

int n, k;
int a[200000];
int f[100004][102];

signed main(){
#define task "a"
    if(fopen(task".inp","r")) {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }

    cin >> n >> k;

    memset(f, 0x3f, sizeof f);
    f[0][1] = 0 ;
    FOR(i ,1, n) cin >> a[i], f[i][1] = max(f[i-1][1], a[i]);
    f[0][1] = 1e9 ;

    FOR(j ,2, k){
        stack <pair <int,int>> st;
        FOR(i ,1, n){
            int mn = f[i-1][j-1];

            while(st.size() && a[st.top().fi] <= a[i]){
                mn = min(mn, st.top().se);
                st.pop();
            }

            f[i][j] = min(mn + a[i], f[st.size() ? st.top().fi : 0][j]);
            st.push(make_pair(i, mn));
        }
    }

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










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

blocks.cpp: In function 'int main()':
blocks.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         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...