# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1106364 | 2024-10-30T04:59:20 Z | tradz | Building Bridges (CEOI17_building) | C++14 | 10 ms | 6480 KB |
#include <bits/stdc++.h> #define int long long #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define For(i,a,b) for(int i = a; i <= b; i++) #define Ford(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define ii pair<int,int> #define fi first #define se second #define all(v) v.begin(),v.end() #define RRH(v) v.resize(unique(all(v)) - v.begin()) using namespace std; const int N = 1e6+7; const int M = 1e9+7; const ll oo = 3e18; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long GetRandom(long long l, long long r) { return uniform_int_distribution<long long> (l, r)(rng); } int n, w[N], h[N]; namespace sub1 { int dp[N], pre[N]; void solve() { pre[0] = 0; For (i, 1, n) pre[i] = pre[i - 1] + w[i]; dp[1] = 0; For (i, 2, n) { dp[i] = oo; for (int j = i - 1; j >= 1; j--) { dp[i] = min(dp[j] + (h[i] - h[j]) * (h[i] - h[j]) + pre[i - 1] - pre[j], dp[i]); } //cout << i << " " << dp[i] << '\n'; } cout << dp[n] << '\n'; } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); #define TASK "" if (fopen (".inp", "r")) { freopen (".inp", "r", stdin); freopen (".out", "w", stdout); } if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } cin >> n; For (i, 1, n) cin >> h[i]; For (i, 1, n) cin >> w[i]; if (n <= 1000) { sub1 :: solve(); return 0; } cerr << "Time elapsed: " << TIME << " s.\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6480 KB | Output is correct |
2 | Correct | 1 ms | 6480 KB | Output is correct |
3 | Correct | 1 ms | 6480 KB | Output is correct |
4 | Correct | 2 ms | 6480 KB | Output is correct |
5 | Correct | 2 ms | 6480 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 5456 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6480 KB | Output is correct |
2 | Correct | 1 ms | 6480 KB | Output is correct |
3 | Correct | 1 ms | 6480 KB | Output is correct |
4 | Correct | 2 ms | 6480 KB | Output is correct |
5 | Correct | 2 ms | 6480 KB | Output is correct |
6 | Incorrect | 10 ms | 5456 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |