Submission #414495

#TimeUsernameProblemLanguageResultExecution timeMemory
414495ak2006Building Bridges (CEOI17_building)C++14
30 / 100
3063 ms4468 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; const ll mod = 1e9 + 7,inf = 1e18; #define pb push_back #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); void setIO() { fast; } int main() { setIO(); int n; cin>>n; vl h(n + 1),w(n + 1),dp(n + 1),p(n + 1); for (int i = 1;i<=n;i++)cin>>h[i]; for (int i = 1;i<=n;i++){cin>>w[i];p[i] = p[i - 1] + w[i];} for (int i = 2;i<=n;i++){ dp[i] = inf; for (int j = i - 1;j>=1;j--){ dp[i] = min(dp[i],dp[j] + (h[i] - h[j]) * (h[i] - h[j]) + p[i - 1] - p[j]); } } cout<<dp[n]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...