제출 #46493

#제출 시각아이디문제언어결과실행 시간메모리
464931KhanBuilding Bridges (CEOI17_building)C++17
0 / 100
3034 ms1636 KiB
#include <bits/stdc++.h> using namespace std; #define Tupizm ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0); #define ONE exit(0); #define nl "\n" #define fly return #define ff first #define ss second #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define pb push_back #define ppb pop_back typedef long long ll; typedef double db; const int N = 1e5 + 5; const int M = 1e9 + 7; int n, h[N], w[N]; ll ans = 1e10; int a[N], b[N]; int main(){ cin >> n; for(int i = 1; i <= n; ++i){ cin >> h[i]; } for(int i = 1; i <= n; ++i){ cin >> w[i]; a[i] = a[i - 1] + w[i]; } for(int i = 2; i < n; ++i){ int q = a[i - 1] + ((h[i] - h[1]) * (h[i] - h[1])); int e = a[n - 1] - a[i] + ((h[i] - h[n]) * (h[i] - h[n])); ans = min(ans, (ll)(q + e)); for(int j = i + 1; j <= n; ++j){ int t = a[j - 1] - a[i] + ((h[j] - h[i]) * (h[j] - h[i])); int y = a[n - 1] - a[j] + ((h[n] - h[j]) * (h[n] - h[j])); ans = min(ans, (ll)(q + t + y)); } } ans = min(ans, (ll)((h[n] - h[1]) * (h[n] - h[1]) + a[n] - a[1])); cout << ans << nl; ONE }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...