Submission #173700

# Submission time Handle Problem Language Result Execution time Memory
173700 2020-01-05T07:24:43 Z itgl K blocks (IZhO14_blocks) C++14
0 / 100
47 ms 41568 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int n, k;
int a[100005];
int dp[100005][105];

int main(){
  cin >> n >> k;
  int sum=0;
  for(int i=1;i<=n;i++){
    cin >> a[i];
    sum+=a[i];

  }
  memset(dp,1e9+7,sizeof(dp));
  dp[0][1]=0;
  for(int i=1;i<=n;i++){
    dp[i][1]=max(dp[i-1][1],a[i]);
  }
  dp[0][1]=1e9+7;

  for(int i=2;i<=k;i++){
    queue<int> pval, val;
    for(int j=1;j<=n;j++){
      int x = dp[j-1][i-1];
      while(!pval.empty()&&a[pval.back()]<a[j]){
        x=min(x,val.back());
        pval.pop();
        val.pop();
      }

      if(pval.size()){
        dp[j][i]=dp[pval.back()][i];

      }
      pval.push(j);
      val.push(min(dp[j][i-1],x));

      dp[j][i]=min(dp[j][i],x+a[j]);

    }
  }

  cout << dp[n][k] << endl;
  return 0;
}
// 10 3 7 9 21 3 9 10 4
# Verdict Execution time Memory Grader output
1 Correct 36 ms 41464 KB Output is correct
2 Correct 36 ms 41464 KB Output is correct
3 Correct 35 ms 41464 KB Output is correct
4 Correct 35 ms 41464 KB Output is correct
5 Correct 35 ms 41464 KB Output is correct
6 Correct 35 ms 41464 KB Output is correct
7 Correct 35 ms 41464 KB Output is correct
8 Correct 35 ms 41464 KB Output is correct
9 Correct 35 ms 41464 KB Output is correct
10 Correct 35 ms 41464 KB Output is correct
11 Incorrect 35 ms 41464 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 41464 KB Output is correct
2 Correct 35 ms 41464 KB Output is correct
3 Correct 35 ms 41464 KB Output is correct
4 Correct 35 ms 41464 KB Output is correct
5 Correct 35 ms 41464 KB Output is correct
6 Correct 35 ms 41464 KB Output is correct
7 Correct 35 ms 41464 KB Output is correct
8 Correct 35 ms 41464 KB Output is correct
9 Correct 35 ms 41404 KB Output is correct
10 Correct 36 ms 41464 KB Output is correct
11 Incorrect 38 ms 41464 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 41464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 41568 KB Output isn't correct
2 Halted 0 ms 0 KB -