Submission #1222024

#TimeUsernameProblemLanguageResultExecution timeMemory
1222024395333emBuilding Bridges (CEOI17_building)C++20
30 / 100
3094 ms3400 KiB
#include <bits/stdc++.h> #define int long long #define emb emplace_back #define pii pair <int, int> using namespace std; const int mod = 1e9 + 7; const int inf = 1e18; const int N = 1e5 + 5; int n, h[N], w[N], pref[N], dp[N]; signed main(){ cin.tie(NULL)->sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) cin >> w[i], pref[i] = pref[i - 1] + w[i]; dp[1] = 0; for (int i = 2; i <= n; i++) dp[i] = inf; for (int i = 2; i <= n; i++) { for (int j = i - 1; j >= 1; j--) { dp[i] = min(dp[i], dp[j] + pref[i - 1] - pref[j] + (h[i] - h[j]) * (h[i] - h[j])); } } cout << dp[n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...