제출 #995664

#제출 시각아이디문제언어결과실행 시간메모리
995664biankAliens (IOI16_aliens)C++14
4 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define all(x) begin(x),end(x) #define sz(x) int(x.size()) #define forn(i,n) for(int i=0;i<int(n);i++) using vi=vector<int>; using ll=long long; using ld=long double; using ii=pair<ll,ll>; #define fst first #define snd second struct Line { ll m,b,k; ll operator()(ll x) { return m*x+b; } ld intersectX(Line &o) { return ld(b-o.b)/(o.m-m); } }; struct LineContainer:deque<Line>{ void add(ll m, ll b, ll k){ Line l=Line{m,b,k}; while(size()>=2&&l.intersectX(begin()[0])<=l.intersectX(begin()[1])) pop_front(); push_front(l); } pair<ll,int> query(ll x){ while(size()>=2&&end()[-1](x)>=end()[-2](x)) pop_back(); return {end()[-1](x),end()[-1].k}; } }; vector<ii> p; ll sq(ll x){ return x*x; } ii check(ll lmd){ LineContainer dp; ll res=0,cnt=0; forn(i,sz(p)){ ll m=-2LL*(p[i].snd-1LL); ll b=res+sq(p[i].snd-1LL); if(i) b-=sq(max(p[i-1].fst-p[i].snd+1LL,0LL)); dp.add(m,b,cnt); tie(res,cnt)=dp.query(p[i].fst); res+=sq(p[i].fst)+lmd,cnt++; } return {res,cnt}; } ll take_photos(int n, int /*m*/, int k, vi r, vi c){ vector<ii> v(n); forn(i,n){ if(r[i]>c[i]) v[i]={r[i],c[i]}; else v[i]={c[i],r[i]}; } sort(all(v),[](const ii &a, ii &b){ if(a.fst==b.fst) return a.snd>b.snd; return a.fst<b.fst; }); forn(i,n){ while(!p.empty()&&p.back().snd>=v[i].snd) p.pop_back(); p.push_back(v[i]); } k=min(k,sz(p)); ll lo=-1e12, hi=1e12; while(hi-lo>1){ ll mid=(hi-lo)/2+lo; if(check(mid).snd<=k) hi=mid; else lo=mid; } return check(hi).fst-k*hi; }
#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...