Submission #939010

#TimeUsernameProblemLanguageResultExecution timeMemory
939010huyboyBuilding Bridges (CEOI17_building)C++17
0 / 100
15 ms2788 KiB
#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 ans = INF; for(int i = 1;i < n - 1;i++){ int check = (h[i] - h[0]) * (h[i] - h[0]) + pref[i] - pref[1]; check += (h[i] - h[n - 1]) * (h[i] - h[n - 1]) + pref[n - 1] - pref[i + 1]; ans = min(ans,check); } int check = (h[n - 1] - h[0]) * (h[n - 1] - h[0]) + pref[n - 1] - pref[1]; ans = min(ans,check); cout << ans << "\n"; } //(h[i] - h[j]) * (h[i] - h[j]) + pref[i] - pref[j + 1] signed main(){ ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0); int t = 1; //~ cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...