Submission #939084

# Submission time Handle Problem Language Result Execution time Memory
939084 2024-03-06T05:28:03 Z vjudge1 Building Bridges (CEOI17_building) C++17
30 / 100
3000 ms 3420 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>*/
template<class S,class T>
bool chmin(S &a,const T &b) {
	return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
	return a<b?(a=b)==b:false;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e18;
const ll mod=998244353;
const ll N=1e5+5;
const ld eps=1e-9;
ll d[N];
void solve(){
    ll i,j;
    ll q;
    ll n;
    cin>>n;
    ll h[n+5],w[n+5];
    ll pref[n+5];
    pref[0]=0;
    for(i=1;i<=n;i++) cin>>h[i];
    for(i=1;i<=n;i++) {
        cin>>w[i];
        pref[i]=pref[i-1]+w[i];
    }
    memset(d,0x3f,sizeof(d));
    d[0]=d[1]=0;
    h[0]=h[1];
    for(i=2;i<=n;i++){
        for(j=i-1;j>0;j--){
            chmin(d[i],d[j]+(h[i]-h[j])*(h[i]-h[j])+pref[i-1]-pref[j]);
        }
    }
    cout<<d[n]<<endl;
}

signed main(){
	start();
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
/*
6
3 8 7 1 6 6
0 -1 9 1 2 0




*/

Compilation message

building.cpp: In function 'void solve()':
building.cpp:48:8: warning: unused variable 'q' [-Wunused-variable]
   48 |     ll q;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3067 ms 3420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Execution timed out 3067 ms 3420 KB Time limit exceeded
7 Halted 0 ms 0 KB -