Submission #1173463

#TimeUsernameProblemLanguageResultExecution timeMemory
1173463DangKhoizzzzBuilding Bridges (CEOI17_building)C++17
30 / 100
1 ms328 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define pii pair <int , int> #define arr3 array <int , 3> using namespace std; const int INF = 1e18; const int maxn = 1e3 + 7; int n , a[maxn] , b[maxn] , dp[maxn]; // nộp hiểu đề bài: void solve() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> b[i]; for(int i = 1; i <= n; i++) dp[i] = INF; dp[1] = 0; for(int i = 2; i <= n; i++) { int sum = 0; for(int j = i-1; j >= 1; j--) { dp[i] = min(dp[i] , dp[j] + sum + (a[i] - a[j])*(a[i] - a[j])); sum += b[j]; } } //for(int i = 1; i <= n; i++) cout << dp[i] << '\n'; cout << dp[n] << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...