Submission #43228

#TimeUsernameProblemLanguageResultExecution timeMemory
432285ak0Building Bridges (CEOI17_building)C++14
0 / 100
3007 ms3812 KiB
/* ID: 5ak0 PROG: LANG: C++11 */ #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mpr make_pair using namespace std; typedef long long ll; typedef pair<int, int> pii; const ll INF = 1e18 + 7; const int MAXN = 1e5 + 10; int n; ll h[MAXN], w[MAXN], pre[MAXN], res = INF; ll dist(int i, int j){ return (h[i] - h[j]) * (h[i] - h[j]); } int main(){ ios_base::sync_with_stdio(0); #ifndef SAKO //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); #endif // SAKO cin >> n; for (int i = 1; i <= n; ++i) cin >> h[i]; for (int i = 1; i <= n; ++i){ cin >> w[i]; pre[i] = pre[i - 1] + w[i]; } for (int i = 2; i < n; ++i) for (int j = i + 1; j < n; ++j) res = min(res, pre[i] - pre[1] + pre[j] - pre[i] + pre[n] - pre[j] + dist(1, i) + dist(i, j) + dist(j, n)); cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...