제출 #684833

#제출 시각아이디문제언어결과실행 시간메모리
684833vjudge1K개의 묶음 (IZhO14_blocks)C++14
0 / 100
35 ms80140 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--)


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]);

    FOR(j ,2, k){
        stack <pair <int,int>> st; 
        FOR(i ,1, n){
            int mn = 1e9; 
            while(st.size() && a[st.top().fi] < a[i]){
                mn = min(mn, st.top().se);
                st.pop();
            }
            f[i][j] = min(f[i][j], mn + a[i]);
            if(st.size()) f[i][j] = min(f[i][j], st.top().se + a[st.top().fi + 1]);

            st.push(make_pair(i, f[i][j-1]));
        }
    }

    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...