Submission #934268

# Submission time Handle Problem Language Result Execution time Memory
934268 2024-02-27T04:36:11 Z Faisal_Saqib Building Bridges (CEOI17_building) C++17
0 / 100
3000 ms 3164 KB
#pragma GCC optimize("unroll-loops")
#include <iostream>
using namespace std;
#define ll long long
const int N=1e5+100;
ll dp[N],a[N],pre[N],h[N],w[N];
ll cost(int i,int j)
{
	if(i>j)
	{
		swap(i,j);
	}
	return pre[i-1]-pre[j]+((h[i]-h[j])*(h[i]-h[j]));
}
void solve()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=1;i<=n;i++)
	{
		cin>>w[i];
		pre[i]=pre[i-1]+w[i];
	}
	ll ans=1e18;
	for(int i=2;i<n;i++)
		for(int j=i+1;j<n;j++)
			ans=min(ans,cost(1,i)+cost(i,j)+cost(j,n));
	cout<<ans;
}
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	int t=1;
	while(t--)
	{
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3064 ms 3164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -