Submission #337230

# Submission time Handle Problem Language Result Execution time Memory
337230 2020-12-19T01:56:42 Z boykut K blocks (IZhO14_blocks) C++14
0 / 100
44 ms 39916 KB
#include <bits/stdc++.h>

using namespace std;

int dp[100001][101], a[100001];

signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   
   int n, k;
   cin >> n >> k;
   
   for (int i = 1; i <= n; i++) {
      cin >> a[i];
   }
  
   for (int i = 0; i <= 100000; i++) {
      for (int j = 0; j <= 100; j++) {
        dp[i][j] = INT_MAX;
      }
   }
   
   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{
      int mx = INT_MIN;
      for (int i = l; i <= r; i++) 
         mx = max(mx, a[i]);
      return mx;
   };
   
   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 28 ms 39916 KB Output is correct
2 Correct 28 ms 39916 KB Output is correct
3 Correct 29 ms 39916 KB Output is correct
4 Correct 29 ms 39916 KB Output is correct
5 Correct 28 ms 39916 KB Output is correct
6 Correct 32 ms 39916 KB Output is correct
7 Correct 28 ms 39916 KB Output is correct
8 Correct 28 ms 39916 KB Output is correct
9 Incorrect 29 ms 39916 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 39916 KB Output is correct
2 Correct 26 ms 39916 KB Output is correct
3 Correct 26 ms 39916 KB Output is correct
4 Correct 26 ms 39916 KB Output is correct
5 Correct 44 ms 39916 KB Output is correct
6 Correct 25 ms 39916 KB Output is correct
7 Correct 25 ms 39916 KB Output is correct
8 Correct 24 ms 39916 KB Output is correct
9 Incorrect 42 ms 39916 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 39916 KB Output is correct
2 Correct 28 ms 39916 KB Output is correct
3 Correct 29 ms 39916 KB Output is correct
4 Correct 29 ms 39916 KB Output is correct
5 Correct 28 ms 39916 KB Output is correct
6 Correct 32 ms 39916 KB Output is correct
7 Correct 28 ms 39916 KB Output is correct
8 Correct 28 ms 39916 KB Output is correct
9 Incorrect 29 ms 39916 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 39916 KB Output is correct
2 Correct 28 ms 39916 KB Output is correct
3 Correct 29 ms 39916 KB Output is correct
4 Correct 29 ms 39916 KB Output is correct
5 Correct 28 ms 39916 KB Output is correct
6 Correct 32 ms 39916 KB Output is correct
7 Correct 28 ms 39916 KB Output is correct
8 Correct 28 ms 39916 KB Output is correct
9 Incorrect 29 ms 39916 KB Output isn't correct
10 Halted 0 ms 0 KB -