Submission #172670

# Submission time Handle Problem Language Result Execution time Memory
172670 2020-01-02T10:28:50 Z Swan K blocks (IZhO14_blocks) C++14
0 / 100
42 ms 41592 KB
#include <cstdio>
#include <cstring>
#include <stack>
#include <algorithm>
using namespace std;

int dp[105][100005];
int a[100005];
int n,k;

int main(){
    scanf("%d %d",&n,&k);
    int maxv = 0;
    memset(dp,0x3f,sizeof(dp));
    for (int i=1; i<=n; i++) {
        scanf("%d",&a[i]);
        maxv = max(maxv,a[i]);
        dp[1][i] = maxv;
    }
    for (int i=2; i<=k; i++) {
        stack<int> s1,s2;
        for (int j=1; j<=n; j++) {
            int my_dp = dp[i-1][j-1];
            while (!s1.empty() && s1.top() < a[j]) {
                my_dp = min(my_dp,s2.top());
                s1.pop();
                s2.pop();
            }
            if(s1.empty()){
                s1.push(a[j]);
                s2.push(my_dp);
            }else{
                s1.push(a[j]);
                s2.push(min(my_dp,dp[i-1][j]));
            }
            if(j >= i) dp[i][j] = s1.top() + s2.top();
        }
    }
    printf("%d",dp[k][n]);
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
blocks.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 41336 KB Output is correct
2 Correct 37 ms 41464 KB Output is correct
3 Correct 37 ms 41336 KB Output is correct
4 Correct 37 ms 41464 KB Output is correct
5 Correct 37 ms 41464 KB Output is correct
6 Correct 37 ms 41464 KB Output is correct
7 Correct 38 ms 41336 KB Output is correct
8 Correct 38 ms 41592 KB Output is correct
9 Correct 37 ms 41444 KB Output is correct
10 Incorrect 37 ms 41464 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 41464 KB Output is correct
2 Correct 37 ms 41464 KB Output is correct
3 Correct 36 ms 41384 KB Output is correct
4 Correct 36 ms 41464 KB Output is correct
5 Correct 36 ms 41444 KB Output is correct
6 Correct 38 ms 41464 KB Output is correct
7 Correct 34 ms 41464 KB Output is correct
8 Correct 36 ms 41436 KB Output is correct
9 Correct 37 ms 41384 KB Output is correct
10 Incorrect 37 ms 41336 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 41336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 41588 KB Output isn't correct
2 Halted 0 ms 0 KB -