제출 #1288085

#제출 시각아이디문제언어결과실행 시간메모리
1288085datluong_04K개의 묶음 (IZhO14_blocks)C++20
100 / 100
165 ms80876 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define FOR(i , a , b) for(int i = a ; i <= b; i++)
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define maxn 100005
#define maxk 105
#define pli pair<ll,int>

ll dp[maxk][maxn] , a[maxn];

int main(){
    if(fopen("blocks.in" , "r")){
        freopen("blocks.in" ,"r" , stdin);
        freopen("blocks.out" , "w" , stdout);
    }
    
    FAST;
    int n , k;
    cin >> n >> k;
    FOR(i , 1 , n) cin >> a[i];
    FOR(i , 0 , k) FOR(j , 0 , n) dp[i][j] = 1e18;
    dp[1][0] = 0;
    dp[0][0] = 0;
    FOR(i , 1 , n) dp[1][i] = max(dp[1][i  - 1] , a[i]);

    FOR(i , 2 , k){
        stack<pli> st;
        FOR(j , 2 , n){
            ll minF = dp[i - 1][j - 1];
            while(!st.empty() && a[st.top().second] <= a[j]){
                minF = min(minF , st.top().first);
                st.pop();
            }

            dp[i][j] = min(dp[i][st.empty() ? 0 : st.top().second] , minF + a[j]);
            st.push(make_pair(minF , j));
        }
    }

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

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

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