제출 #673410

#제출 시각아이디문제언어결과실행 시간메모리
673410vjudge1Cover (COCI18_cover)C++14
120 / 120
3 ms468 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pii pair<ll,ll> #define pb push_back const int N = 5005; int n; ll dp[N]; map<int,int> mp; vector<pii> myVec; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1, x, y; i <= n; i++) { cin >> x >> y; x = abs(x), y = abs(y); auto it = mp.find(x); if (it == mp.end()) mp[x] = y; else mp[x] = max(y, it->se); } for (auto it : mp) { while (!myVec.empty() && it.se >= myVec.back().se) myVec.pop_back(); myVec.pb(it); } n = myVec.size(); for (int i = 0; i < n; i++) { dp[i] = 4 * myVec[i].fi * myVec[0].se; for (int j = 0; j < i; j++) dp[i] = min(dp[i], dp[j] + 4 * myVec[i].fi * myVec[j + 1].se); } cout << dp[n - 1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...