이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1e9+7;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t z;
const int mxn = 2e5+5;
int n;
ll h[mxn];
ll w[mxn];
ll dp[mxn];
ll pref[mxn];
ll p(ll a){
return a*a;
}
void solve(){
cin >> n;
fr(i, 0, n){
cin >> h[i];
}
fr(i, 0, n){
cin >> w[i];
}
pref[0] = w[0];
fr(i, 1, n){
pref[i] = pref[i-1]+w[i];
}
dp[0] = 0;
fr(i, 1, n){
dp[i] = inf;
fr(j, 0, i){
dp[i] = min(dp[i], dp[j] + (pref[i] - pref[j] - w[i]) + p(h[i]-h[j]));
}
}
cout<<dp[n-1]<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |