Submission #1060351

# Submission time Handle Problem Language Result Execution time Memory
1060351 2024-08-15T13:15:35 Z 0pt1mus23 K blocks (IZhO14_blocks) C++14
0 / 100
5 ms 57920 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]=0x3f;
        }
    }
    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<int> s1,s2;
        for(int j=1;j<=n;j++){
            int md = dp[i-1][j-1];
            while(!s1.empty() && s1.top() < arr[j]){
                md = min(md,s2.top());
                s1.pop();
                s2.pop();
            }
            if(s1.empty() || md + arr[j] < s1.top() + s2.top()){
                s1.push(arr[j]);
                s2.push(md);
            }
            if(j>=i){
                dp[i][j] = s1.top() + s2.top();
            }
        }
    }
    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 0 ms 2396 KB Output is correct
2 Correct 0 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 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 4 ms 49756 KB Output is correct
13 Incorrect 5 ms 57920 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2408 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 8704 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Incorrect 2 ms 16984 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 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 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 4 ms 49756 KB Output is correct
13 Incorrect 5 ms 57920 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 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 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 4 ms 49756 KB Output is correct
13 Incorrect 5 ms 57920 KB Output isn't correct
14 Halted 0 ms 0 KB -