# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1051267 | 2024-08-10T02:42:51 Z | vu28082007 | Building Bridges (CEOI17_building) | C++14 | 10 ms | 3804 KB |
#include <bits/stdc++.h> using namespace std; #define taskname "mvu" #define ll long long #define fi first #define se second #define pb push_back const int N = 1e5+7; ll n, h[N], w[N], f[5007], b[N]; void sub1() { for (int i = 2; i <= n; i++) { for (int j = 1; j < i; j++) { f[i]=min(f[i], f[j]+(h[i]-h[j])*(h[i]-h[j]) + b[i-1]-b[j]); } } cout << f[n]; } void mvu() { cin >> n; for (int i = 1; i <= n; i++) { f[i]=1e18; cin >> h[i]; } f[1]=0; for (int i = 1; i <= n; i++) { cin >> w[i]; if(i > 1 && i < n) b[i]=b[i-1]+w[i]; } if (n <= 5000) { sub1(); return; } ll sum1=0; sum1=b[n-1]+(h[n]-h[1])*(h[n]-h[1]); for (int i =2; i < n; i++) { sum1=min(sum1, (b[n-1]-w[i]) + (h[i]-h[1])*(h[i]-h[1]) + (h[i]-h[n])*(h[i]-h[n])); } cout << sum1; } int main() { if(fopen(taskname".inp","r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); mvu(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2476 KB | Output is correct |
4 | Correct | 1 ms | 2512 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 3676 KB | Output is correct |
2 | Correct | 8 ms | 3804 KB | Output is correct |
3 | Incorrect | 9 ms | 3672 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2476 KB | Output is correct |
4 | Correct | 1 ms | 2512 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 10 ms | 3676 KB | Output is correct |
7 | Correct | 8 ms | 3804 KB | Output is correct |
8 | Incorrect | 9 ms | 3672 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |