제출 #32204

#제출 시각아이디문제언어결과실행 시간메모리
32204dongwon0427Aliens (IOI16_aliens)C++11
100 / 100
286 ms11792 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,ld> pil; struct _tuple { int x,y; }; _tuple A[100005],B[100005]; int n; ld dp[100005]; int gaesu[100005]; struct line { ld tan,y; int idx; }; inline ld inter(line a,line b) { return (b.y-a.y)/(a.tan-b.tan); } line L[100005]; int check1(line a,line b,line c) { return (b.y-a.y)*(b.tan-c.tan) >= (c.y-b.y)*(a.tan-b.tan); //return inter(a,b) >= inter(b,c); } int check2(line a,line b,int c) { return b.y-a.y < (ld)(c) * (a.tan-b.tan); //return inter(a,b) < (ld)c; } pil CHT(ld c) { gaesu[0]=0; dp[1] = (ld)(A[1].y-A[1].x+1)*(ld)(A[1].y-A[1].x+1)-c; gaesu[1]=1; int sz = 0; int p=0; for(int i=2;i<=n;i++) { dp[i] = (ld)(A[i].y-A[1].x+1)*(ld)(A[i].y-A[1].x+1)-c; int minidx = 0; line ins; ins.idx = i-1; ins.y = dp[i-1] - (ld)max(0,-A[i].x+A[i-1].y+1)*(ld)max(0,-A[i].x+A[i-1].y+1) + (ld)(A[i].x)*(ld)(A[i].x) - (ld)(2*A[i].x); ins.tan = (ld)(-2 * A[i].x); while(sz>=2 && check1(L[sz-2],L[sz-1],ins)) { if(p==sz-1) p--; sz--; } L[sz++] = ins; while(p<sz-1 && check2(L[p],L[p+1],A[i].y)) p++; if(dp[i] > (ld)(1) - c + (ld)(2*A[i].y) + (ld)(A[i].y)*(ld)(A[i].y) + L[p].tan*(ld)(A[i].y) + L[p].y) { dp[i] = (ld)(1) - c + (ld)(2*A[i].y) + (ld)(A[i].y)*(ld)(A[i].y) + L[p].tan*(ld)(A[i].y) + L[p].y; minidx = L[p].idx; } gaesu[i] = gaesu[minidx] + 1; } return pil(gaesu[n],dp[n]); /*gaesu[0]=0; for(int i=1;i<=n;i++) { dp[i] = (ld)(A[i].y-A[1].x+1)*(ld)(A[i].y-A[1].x+1)-c; int minidx = 0; for(int j=1;j<i;j++) { if( dp[i] > dp[j] + (ld)(A[i].y-A[j+1].x+1)*(ld)(A[i].y-A[j+1].x+1) - (ld)max(0,-A[j+1].x+A[j].y+1)*(ld)max(0,-A[j+1].x+A[j].y+1) - c ) { minidx = j; dp[i] = dp[j] + (ld)(A[i].y-A[j+1].x+1)*(ld)(A[i].y-A[j+1].x+1) - (ld)max(0,-A[j+1].x+A[j].y+1)*(ld)max(0,-A[j+1].x+A[j].y+1) - c; } } gaesu[i] = gaesu[minidx]+1; } return pil(gaesu[n],dp[n]);*/ } ll take_photos(int N, int m, int k, std::vector<int> r, std::vector<int> c) { for(int i=0;i<N;i++) { B[i].x=r[i]; B[i].y=c[i]; if(B[i].x > B[i].y) swap(B[i].x,B[i].y); } sort(B,B+N,[](_tuple a,_tuple b){return a.x>b.x;}); for(int i=0;i<N;i++) { while(n!=0 && A[n].y <= B[i].y) { n--; } A[++n] = B[i]; } reverse(A+1,A+1+n); if(k>n) k = n; ll bs = -(ll)m*(ll)m-1ll, be = 0; int lft=1,rht=n; ll L=(ll)m*(ll)m,R=(ll)m*(ll)m; while(bs<=be) { ll bm = (bs+be)/2; //printf("%d\n",bm); ld gi = (ld)bm + (ld)0.5; pil tmp = CHT(gi); if(tmp.first==k) { return (long long)(tmp.second + gi*(ld)(k)); } if(tmp.first > k) { be=bm-1; if(rht >= tmp.first) { rht = tmp.first; R = (ll)(tmp.second + gi*(ld)(tmp.first)); } } else { bs=bm+1; if(lft <= tmp.first) { lft = tmp.first; L = (ll)(tmp.second + gi*(ld)(tmp.first)); } } } return (L*(ll)(rht-k) + R*(ll)(k-lft)) / (ll)(-lft+rht); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...