Submission #1059741

# Submission time Handle Problem Language Result Execution time Memory
1059741 2024-08-15T07:40:59 Z NeroZein Nestabilnost (COI23_nestabilnost) C++17
0 / 100
2 ms 860 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

const int N = 5002;

int a[N];
int f[N];
int suf[N];
long long dp[N];
vector<int> g[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> f[i];
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u); 
  }
  suf[n] = f[n];
  for (int i = n - 1; i >= 1; --i) {
    suf[i] = min(suf[i + 1], f[i]); 
  }
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1] + suf[a[i] + 1];
    int mx = a[i], d = -1;
    for (int j = i - 1; j > 0; --j) {
      if (a[j + 1] > a[j] + 1) {
        break; 
      }
      if (a[j + 1] == 0) {
        if (d != -1 && d != a[j]) break;
        d = a[j] + 1;
      } else if (a[j + 1] <= a[j]) {
        break;
      } 
      mx = max(mx, a[j]);
      if (d != -1 && mx >= d) {
        break; 
      }
      dp[i] = min(dp[i], dp[j - 1] + (d != -1 ? f[d] : suf[mx + 1]));
    }
    //debug(i, dp[i]);
  }
  cout << dp[n] << '\n'; 
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -