Submission #548362

# Submission time Handle Problem Language Result Execution time Memory
548362 2022-04-13T06:31:43 Z Soumya1 Skyline (IZhO11_skyline) C++17
0 / 100
3 ms 640 KB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 301;
const int mxH = 201;
const int inf = 1e9;
int h[mxN];
void testCase() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> h[i];
  vector<vector<int>> dp(mxH, vector<int> (mxH, inf));
  for (int i = h[1]; i >= 0; i--) {
    dp[0][i] = (h[1] - i) * 3;
  }
  for (int i = 2; i <= n; i++) {
    vector<vector<int>> new_dp(mxH, vector<int> (mxH, inf));
    for (int cur = 0; cur <= h[i]; cur++) {
      for (int last = 0; last <= h[i - 1]; last++) {
        new_dp[last][cur] = min(new_dp[last][cur], dp[h[i] - cur][last + h[i] - cur] + (h[i] - cur) * 7);
      }
    }
    dp = new_dp;
    for (int cur = h[i]; cur >= 0; cur--) {
      for (int last = h[i - 1]; last >= 0; last--) {
        if (last - 1 >= 0) {
          dp[last - 1][cur] = min(dp[last - 1][cur], dp[last][cur] + 3);
        }
        if (cur - 1 >= 0 && last - 1 >= 0) {
          dp[last - 1][cur - 1] = min(dp[last - 1][cur - 1], dp[last][cur] + 5);
        }
        if (cur - 1 >= 0) {
          dp[last][cur - 1] = min(dp[last][cur - 1], dp[last][cur] + 3);
        }
      }
    }
  }
  cout << dp[0][0] << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Incorrect 2 ms 640 KB Output isn't correct
10 Halted 0 ms 0 KB -