Submission #337225

# Submission time Handle Problem Language Result Execution time Memory
337225 2020-12-19T01:48:40 Z boykut K blocks (IZhO14_blocks) C++14
0 / 100
1 ms 492 KB
#include <bits/stdc++.h>

using namespace std;

int dp[100001][101];

signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   
   int n, k;
   cin >> n >> k;
   int a[1 + n]; a[0] = 0;
   
   for (int i = 1; i <= n; i++) {
      cin >> a[i];
   }
   
   dp[0][0] = 0;
   dp[1][1] = a[1];
   for (int i = 2; i <= n; i++) {
      dp[i][1] = max(dp[i - 1][1], a[i]);
   }
   
   auto getmax = [&](int l, int r) -> int{
      return *max_element(a + l, a + r + 1);
   };
   
   for (int j = 2; j <= k; j++) {
      for (int i = 1; i <= n; i++) {
         int mn = INT_MAX;
         for (int l = 1; l < i; l++) {
            mn = min(mn, dp[l][j - 1] + getmax(l + 1, i));
         }
         dp[i][j] = mn;
      }
   }
   
   cout << dp[n][k] << '\n';
   
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Incorrect 0 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 0 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Incorrect 0 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Incorrect 0 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -