답안 #934297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934297 2024-02-27T06:32:12 Z Faisal_Saqib Building Bridges (CEOI17_building) C++17
30 / 100
3000 ms 3416 KB
#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];
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];
	for(int i=1;i<=n;i++)
		pre[i]=pre[i-1]+w[i];
	for(int i=1;i<=n;i++)
		dp[i]=1e18;
	dp[1]=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			dp[j]=min(dp[j],dp[i]+(pre[j-1]-pre[i])+((h[j]-h[i])*(h[j]-h[i])));
	cout<<dp[n];
}
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	int t=1;
	while(t--)
	{
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3099 ms 3416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Execution timed out 3099 ms 3416 KB Time limit exceeded
7 Halted 0 ms 0 KB -