Submission #1060283

# Submission time Handle Problem Language Result Execution time Memory
1060283 2024-08-15T12:38:50 Z 0pt1mus23 K blocks (IZhO14_blocks) C++14
0 / 100
1 ms 2396 KB
#pragma GCC optimize("O3")
 
#include <bits/stdc++.h> 
using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ins insert
#define pb push_back
#define int long long int
#define pii pair<int, int>
#define endl '\n' 
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
#define hash z0hashp
#define div  z0dvp
const int mod = 1e9 +7, sze = 1e6+23, inf = LLONG_MAX, P = 1453;
int dp[200][100000];
void opt1z(){
    int n,k;
    cin>>n>>k;
    vector<int> arr(n+1);
    int mx =0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=k;j++){
            dp[i][j]=inf;
        }
    }
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        mx=max(mx,arr[i]);
        dp[1][i]=mx;
    }
    for(int i=2;i<=k;i++){
        stack<pair<int,int>> lst;
        for(int j=1;j<=n;j++){
            int mdp =dp[i-1][j-1];

            while(!lst.empty() && lst.top().first<arr[j]){
                mdp = min(mdp,lst.top().second);
                lst.pop();
            }
            if(lst.empty() || mdp+ arr[j]<lst.top().first + lst.top().second){
                lst.push({arr[j],mdp});
            }
            
            if(j>=i){
                dp[i][j]=lst.top().first + lst.top().second;
                // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            }
        }

    }
    drop(dp[k][n]);

}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int tt = 1;
    // cin>>tt;
    while(tt--){
        opt1z();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -