Submission #1165852

#TimeUsernameProblemLanguageResultExecution timeMemory
1165852LmaoLmaoK blocks (IZhO14_blocks)C++20
0 / 100
1096 ms320 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;

using ll = long long;
using ii = pair<ll, ll>;
using aa = array<int,3>;

const int N = 1e6+5;
const int INF = 1e9;

int dp[10005][105];
int a[10005];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int n,k;
    cin >> n >> k;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
    }
    for(int j=1;j<=k;j++) {
        stack<int> st;
        dp[j-1][j]=1e18;
        for(int i=j;i<=n;i++) {
            while(!st.empty() && a[i]>=a[st.top()]) {
                st.pop();
            }
            int pos;
            if(st.empty()) {
                pos=j-1;
            }
            else {
                pos=st.top()-1;
            }
            dp[i][j]=min(dp[pos][j-1]+a[i],dp[pos][j]);
        }
    }
    cout << dp[n][k];
    return 0;
}

Compilation message (stderr)

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