이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
//"\n"
//__builtin_popcount
using namespace std;
const int tam=1005;
int n;
ll dp[tam][tam];
vi h,w;
ll f(int pos, int ant){
if(pos==n-1)return (h[pos]-h[ant])*(h[pos]-h[ant]);
if(dp[pos][ant]!=-1)return dp[pos][ant];
dp[pos][ant]=w[pos]+f(pos+1,ant);
dp[pos][ant]=min(dp[pos][ant],(h[pos]-h[ant])*(h[pos]-h[ant])+f(pos+1,pos));
return dp[pos][ant];
}
int main()
{
cin>>n;
int x;
for(int i=0;i<n;i++){
cin>>x;
h.pb(x);
}
for(int i=0;i<n;i++){
cin>>x;
w.pb(x);
}
memset(dp,-1,sizeof(dp));
cout<<f(1,0)<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |