답안 #939038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939038 2024-03-06T04:11:13 Z vjudge1 Building Bridges (CEOI17_building) C++17
0 / 100
35 ms 2768 KB
#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 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2768 KB Output is correct
2 Correct 35 ms 2556 KB Output is correct
3 Correct 35 ms 2652 KB Output is correct
4 Correct 33 ms 2764 KB Output is correct
5 Incorrect 34 ms 2652 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -