Submission #217342

#TimeUsernameProblemLanguageResultExecution timeMemory
217342vanicCover (COCI18_cover)C++14
12 / 120
8 ms768 KiB
#include <iostream> #include <cstdio> #include <math.h> #include <algorithm> #include <vector> #include <set> /* #include <dora> #include <vito> */ #include <string> #include <map> #include <queue> //#include <> using namespace std; typedef long long ll; const int maxn=5005; const ll inf=1e18; int n; map < pair < int, int >, bool > bio; vector < pair < int, int > > v; deque < pair < int, int > > q; ll dp[maxn]; ll binary(int x){ int lo=0, hi=x, mid; while(lo<hi){ mid=(lo+hi)/2; if(mid){ if(dp[mid-1]+(ll)v[mid].second*v[x].first<dp[mid]+(ll)v[mid+1].second*v[x].first){ hi=mid; } else{ lo=mid+1; } } else{ if((ll)v[mid].second*v[x].first<dp[mid]+(ll)v[mid+1].second*v[x].first){ hi=mid; } else{ lo=mid+1; } } } if(lo){ return dp[lo-1]+(ll)v[lo].second*v[x].first; } else{ return (ll)v[lo].second*v[x].first; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; pair < int, int > p; for(int i=0; i<n; i++){ cin >> p.first >> p.second; p.first=abs(p.first); p.second=abs(p.second); if(!bio[p]){ bio[p]=1; v.push_back(p); } } n=v.size(); sort(v.begin(), v.end()); for(int i=0; i<n; i++){ while(!q.empty() && q.back().second<=v[i].second){ q.pop_back(); } q.push_back(v[i]); } v.clear(); while(!q.empty()){ v.push_back(q.front()); q.pop_front(); } n=v.size(); for(int i=0; i<n; i++){ dp[i]=binary(i); } cout << dp[n-1]*4 << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...