제출 #349382

#제출 시각아이디문제언어결과실행 시간메모리
349382dooweyBuilding Bridges (CEOI17_building)C++14
30 / 100
3071 ms3308 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)1e5 + 10; const ll inf = (ll)1e18; int h[N]; ll w[N]; ll dp[N]; ll sq(ll x){ return (x * 1ll * x); } int main(){ fastIO; int n; cin >> n; for(int i = 1; i <= n; i ++ ){ cin >> h[i]; } for(int i = 1; i <= n; i ++ ){ cin >> w[i]; w[i] += w[i - 1]; dp[i]=inf; } dp[1]=0; for(int i = 2; i <= n; i ++ ){ for(int j = i - 1; j >= 1; j -- ){ dp[i]=min(dp[i],(w[i-1]-w[j])+sq(h[i]-h[j])+dp[j]); } } cout << dp[n]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...