#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pb push_back
#define fr first
#define sc second
const long long INF=1e17,N=2e5+6;
int h[N],c[N];
int f(int l, int r){
int val=(h[r]-h[l])*(h[r]-h[l]);
for(int i=l+1;i<r;i++)
val+=c[i];
int res=val, md=-1;
int sum=res-(h[r]-h[l])*(h[r]-h[l]);
for(int i=l+1;i<r;i++){
int tmp=(sum-c[i]+(h[l]-h[i])*(h[l]-h[i])+
(h[r]-h[i])*(h[r]-h[i]));
if(tmp<res){
res=tmp;
md=i;
}
}
if(md==-1) return res;
return f(l,md)+f(md,r);
}
void solve(){
int n;cin>>n;
for(int i=1;i<=n;i++)
cin>>h[i];
for(int i=1;i<=n;i++)
cin>>c[i];
int v=(h[n]-h[1])*(h[n]-h[1]);
for(int i=2;i<n;i++)
v+=c[i];
cout<<f(1,n);
}
main(){
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message
building.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
504 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
1172 KB |
Output is correct |
2 |
Correct |
35 ms |
1148 KB |
Output is correct |
3 |
Correct |
36 ms |
1108 KB |
Output is correct |
4 |
Correct |
33 ms |
1116 KB |
Output is correct |
5 |
Incorrect |
37 ms |
1108 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
504 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |