이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const ll MAXH = 1e6 + 10;
const ll MAXW = 1e6 + 10;
const ll INF = 4e18 + 10;
int n;
ll h[MAXN];
ll w[MAXN];
ll prefw[MAXN];
ll dp[MAXN][2];
void read()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> h[i];
}
for(int i = 1; i <= n; i++)
{
cin >> w[i];
prefw[i] = prefw[i - 1] + w[i];
dp[i][0] = dp[i][1] = INF;
}
}
ll query(ll left, ll right)
{
if(left > right)
return 0LL;
return prefw[right] - prefw[left - 1];
}
void solve()
{
dp[1][0] = dp[1][1] = 0;
for(int i = 2; i <= n; i++)
{
dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + w[i];
for(int j = i - 1; j >= 1; j--)
{
dp[i][1] = min(dp[i][1], dp[j][1] + query(j + 1, i - 1) + (h[i] - h[j]) * (h[i] - h[j]));
}
}
cout << dp[n][1] << endl;
}
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |