답안 #939051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939051 2024-03-06T04:32:37 Z vjudge1 Building Bridges (CEOI17_building) C++17
0 / 100
41 ms 2652 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;
	vector<int> md;
	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.clear();
			md.pb(i);
		}
		else if(tmp==res){
			md.pb(i);
		}
	}
	if(md.size()==0) return res;
	for(auto it: md){
		res=min(res,f(l,it)+f(it,r));
	}
	return res;
}
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];
		
	cout<<f(1,n);
}
main(){
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
}

Compilation message

building.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 2652 KB Output is correct
2 Correct 38 ms 2644 KB Output is correct
3 Correct 41 ms 2644 KB Output is correct
4 Correct 34 ms 2640 KB Output is correct
5 Incorrect 35 ms 2644 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -