답안 #939000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939000 2024-03-06T03:20:21 Z vjudge1 Building Bridges (CEOI17_building) C++17
30 / 100
3000 ms 4404 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 dp[n + 1];
	dp[0] = 0;
	for(int i = 1;i < n;i++){
		for(int j = 0;j < i;j++){
			if(j == 0){
				dp[i] = (h[i] - h[j]) * (h[i] - h[j]) + pref[i] - pref[j + 1]; 
			} else{
				dp[i] = min(dp[i],(h[i] - h[j]) * (h[i] - h[j]) + pref[i] - pref[j + 1] + dp[j]); 
			}
		}
	}
	cout << dp[n - 1] << "\n";
}
 
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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3094 ms 4404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Execution timed out 3094 ms 4404 KB Time limit exceeded
7 Halted 0 ms 0 KB -