Submission #9127

#TimeUsernameProblemLanguageResultExecution timeMemory
9127maniacWall construction (kriii2_WA)C++98
4 / 4
0 ms1228 KiB
#include <cstdio> #include <cmath> #include <algorithm> #include <vector> #define INF 1600000001 using namespace std; typedef pair <long long, long long> ll; ll st=ll(INF, INF); int ccw(ll a, ll b, ll c){ long long t = a.first*b.second - a.second*b.first; t += b.first*c.second - b.second*c.first; t += c.first*a.second - c.second*a.first; if(t>0) return 1; else if(t<0) return -1; else return 0; } bool comp(ll a, ll b){ return ccw(st, a, b) < 0; } vector <ll> convex_hull( vector <ll> &p ){ vector <ll> re; sort(p.begin(), p.end()); st = p[0]; stable_sort(p.begin()+1, p.end(), comp); int l=p.size(); for(int i=0; i<l; i++){ while(re.size()>=2 && ccw(re[re.size()-2], re[re.size()-1], p[i]) >=0 ) re.pop_back(); re.push_back(p[i]); } return re; } double dist( ll a, ll b ){ return sqrt( (double)(a.first-b.first)*(a.first-b.first) + (a.second-b.second)*(a.second-b.second) ); } int main(){ vector <ll> p; long long n, a, b; double r; scanf("%lld %lf", &n, &r); for(int i=0; i<n; i++){ scanf("%lld %lld", &a, &b); p.push_back(ll(a, b)); } vector <ll> c = convex_hull( p ); int sz = c.size(); double ans = 2*r*acos(-1.0); for(int i=0; i<sz; i++) ans += dist( c[i], c[(i+1)%sz] ); printf("%.13f\n", ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...