Submission #939035

# Submission time Handle Problem Language Result Execution time Memory
939035 2024-03-06T04:00:39 Z vjudge1 Building Bridges (CEOI17_building) C++17
30 / 100
3000 ms 2788 KB
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   @  |    |  |  | /   /| |\  | /   |  |  @ | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///* 
 
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define int long long
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef vector<pii> vii;
const int N = 3e5+50, inf = 1e18, mod = 1e9+7;

void solve(){
	int n;
	cin >> n;
	int a[n], w[n];
	for(int &i:a)cin >> i;
	for(int &i:w)cin >> i;
	
	int ans[n]{};
	for(auto &i:ans)i = inf;
	ans[0] = 0;
	
	for(int i = 1; i < n; i++){
		int sm = 0;
		for(int j = i - 1; j >= 0; j--){
			int df = a[i]-a[j];df*=df;
			ans[i] = min(ans[i], ans[j] + sm + df);
			sm += w[j];
		}
	}
	
	//for(int i:ans)cout << i << ' ' ;
	//cout << '\n';
	cout << ans[n-1] << '\n';
	
}
main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int test = 1;
	//cin >> test;
	while(test--){
		solve();
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 

Compilation message

building.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 2788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Execution timed out 3058 ms 2788 KB Time limit exceeded
7 Halted 0 ms 0 KB -