# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
217368 |
2020-03-29T13:25:41 Z |
vanic |
Cover (COCI18_cover) |
C++14 |
|
8 ms |
768 KB |
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
/*
#include <dora>
#include <vito>
*/
#include <map>
#include <queue>
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];
vector < pair < ll, ll > > ljusk;
bool ccw(pair < ll, ll > a, pair < ll, ll > b, pair < ll, ll > c){
return a.first*(b.second-c.second)+b.first*(c.second-a.second)+c.first*(a.second-b.second)>0;
}
void dodaj(pair < ll, ll > p){
// cout << "dodaj" << endl;
// cout << p.first << " " << p.second << '\n';
while(ljusk.size()>1 && !ccw(p, ljusk.back(), ljusk[ljusk.size()-2])){
// cout << "brisi" << endl;
// cout << ljusk.back().first << " " << ljusk.back().second << endl;
ljusk.pop_back();
}
ljusk.push_back(p);
}
ll query(ll x, ll y){
int lo=0, hi=ljusk.size()-1, mid;
while(lo<hi){
mid=(lo+hi)/2;
if(ljusk[mid].first*x+ljusk[mid].second*y<ljusk[mid+1].first*x+ljusk[mid+1].second*y){
hi=mid;
}
else{
lo=mid+1;
}
}
/* for(int i=0; i<ljusk.size(); i++){
cout << ljusk[i].first*x+ljusk[i].second*y << " ";
}
cout << '\n';*/
return ljusk[lo].first*x+ljusk[lo].second*y;
}
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();
/* cout << "A niz je" << endl;
for(int i=0; i<n; i++){
cout << v[i].first << " " << v[i].second << '\n';
}
cout << "................" << endl;*/
dodaj({v[0].second, 0});
for(int i=0; i<n; i++){
dp[i]=query(v[i].first, 1);
if(i<n-1){
dodaj({v[i+1].second, dp[i]});
}
}
/* for(int i=0; i<n; i++){
cout << dp[i] << " ";
}
cout << '\n';*/
cout << dp[n-1]*4 << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
640 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |