Submission #468997

# Submission time Handle Problem Language Result Execution time Memory
468997 2021-08-30T11:07:20 Z paga2004 Building Bridges (CEOI17_building) C++14
30 / 100
34 ms 19500 KB
#include <bits/stdc++.h>

#ifdef LOCAL
#define dbg(x) cerr << "dgb: " << x << "\n";
#else
#define dbg(x)
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,tune=native")
#endif

#define int int_fast64_t

using namespace std;

const int INF = 1e17;
vector<int> hs;
vector<int> w;
int n;
vector<vector<int>> memo(1001, vector<int>(1001, INF));

int f(int i, int l) {
  if (memo[i][l] != INF)
    return memo[i][l];
  if (i == 0)
    return (hs[l] - hs[0]) * (hs[l] - hs[0]);
  int best = f(i - 1, i) + (hs[i] - hs[l]) * (hs[i] - hs[l]);
  if (i != n - 1)
    best = min(best, f(i - 1, l) + w[i]);

  return memo[i][l] = best;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n;
  hs.resize(n);
  w.resize(n);
  for (int &x : hs)
    cin >> x;
  for (int &x : w)
    cin >> x;

  cout << f(n - 1, n - 1) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 4 ms 8140 KB Output is correct
3 Correct 4 ms 8140 KB Output is correct
4 Correct 16 ms 8140 KB Output is correct
5 Correct 16 ms 8240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 19500 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 4 ms 8140 KB Output is correct
3 Correct 4 ms 8140 KB Output is correct
4 Correct 16 ms 8140 KB Output is correct
5 Correct 16 ms 8240 KB Output is correct
6 Runtime error 34 ms 19500 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -