Submission #250658

#TimeUsernameProblemLanguageResultExecution timeMemory
250658SortingBuilding Bridges (CEOI17_building)C++14
30 / 100
3036 ms2596 KiB
#include <bits/stdc++.h> using namespace std; const int k_N = 1e5 + 3; const long long k_Inf = 1e18; int n; long long h[k_N], w[k_N]; long long dp[k_N]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 0; i < n; ++i) cin >> h[i]; for(int i = 0; i < n; ++i) cin >> w[i]; dp[n - 1] = 0; for(int i = n - 2; i >= 0; --i){ dp[i] = k_Inf; long long sum = 0; for(int j = i + 1; j <= n - 1; ++j){ dp[i] = min(sum + (h[i] - h[j]) * (h[i] - h[j]) + dp[j], dp[i]); sum += w[j]; } } cout << dp[0] << "\n"; } /* 6 3 8 7 1 6 6 0 -1 9 1 2 0 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...