제출 #468986

#제출 시각아이디문제언어결과실행 시간메모리
468986JosiaBuilding Bridges (CEOI17_building)C++17
30 / 100
3091 ms3784 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> #define int int64_t using namespace std; vector<int> pfs = {0}; vector<int> mem; int dp(vector<pair<int, int>>& pillars, int lenght) { if (lenght == 0) { return 0; } if (mem[lenght] != 1e17) return mem[lenght]; int res = 1e17; for (int i = 0; i<lenght; i++) { res = min(res, dp(pillars, i) + (pfs[lenght] - pfs[i+1]) + (pillars[i].first - pillars[lenght].first) * (pillars[i].first - pillars[lenght].first)); } return mem[lenght] = res; } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; mem.assign(n, 1e17); vector<pair<int, int>> pillars(n); for (int i = 0; i<n; i++) { cin >> pillars[i].first; } for (int i = 0; i<n; i++) { cin >> pillars[i].second; pfs.push_back(pfs.back() + pillars[i].second); } pillars[0].second = 0; pillars.back().second = 0; cout << dp(pillars, n-1) << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...