답안 #939007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939007 2024-03-06T03:26:29 Z vjudge1 Building Bridges (CEOI17_building) C++17
0 / 100
12 ms 2652 KB
#include "bits/stdc++.h"
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds; 
 
using namespace std;
 
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
const int INF = 1e18;
 
void solve(){	
	
	int n;
	cin >> n;
	int h[n],w[n];
	for(int i = 0;i < n;i++){
		cin >> h[i];
	}
	for(int i = 0;i < n;i++){
		cin >> w[i];
	}
	int pref[n + 1];
	pref[0] = 0;
	for(int i = 0;i < n;i++){
		pref[i + 1] = pref[i] + w[i];
	}
	int ans = INF;
	for(int i = 1;i < n - 1;i++){
		int check = (h[i] - h[0]) * (h[i] - h[0]) + pref[i] - pref[1];
		check += (h[i] - h[n - 1]) * (h[i] - h[n - 1]) + pref[n - 1] - pref[i + 1];
		ans = min(ans,check);
	}
	int check = (h[n - 1] - h[0]) * (h[n - 1] - h[0]) + pref[n - 1] - pref[1];
	ans = min(ans,check);
	cout << ans << "\n";
}
//(h[i] - h[j]) * (h[i] - h[j]) + pref[i] - pref[j + 1]
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	
	int t = 1;
	//~ cin >> t;
	while(t--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 2652 KB Output is correct
2 Correct 12 ms 2652 KB Output is correct
3 Incorrect 12 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -