結果
問題 | No.2012 Largest Triangle |
ユーザー | eQe |
提出日時 | 2024-08-25 03:09:44 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 9,872 bytes |
コンパイル時間 | 6,280 ms |
コンパイル使用メモリ | 337,404 KB |
実行使用メモリ | 15,156 KB |
最終ジャッジ日時 | 2024-08-25 03:10:00 |
合計ジャッジ時間 | 15,706 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 3 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 261 ms
14,572 KB |
testcase_17 | AC | 257 ms
14,560 KB |
testcase_18 | AC | 250 ms
14,400 KB |
testcase_19 | AC | 249 ms
14,404 KB |
testcase_20 | WA | - |
testcase_21 | AC | 292 ms
14,556 KB |
testcase_22 | AC | 253 ms
14,428 KB |
testcase_23 | AC | 251 ms
14,428 KB |
testcase_24 | AC | 246 ms
14,572 KB |
testcase_25 | AC | 241 ms
14,560 KB |
testcase_26 | AC | 380 ms
14,432 KB |
testcase_27 | AC | 356 ms
14,428 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 358 ms
14,640 KB |
testcase_31 | AC | 277 ms
14,440 KB |
testcase_32 | WA | - |
testcase_33 | AC | 296 ms
14,556 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 4 ms
6,940 KB |
testcase_37 | AC | 3 ms
6,940 KB |
testcase_38 | AC | 3 ms
6,940 KB |
testcase_39 | AC | 3 ms
6,940 KB |
testcase_40 | AC | 3 ms
6,940 KB |
testcase_41 | WA | - |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> namespace my{ using namespace atcoder; using ml=modint998244353; auto&operator<<(std::ostream&o,const ml&x){return o<<x.val();} auto&operator>>(std::istream&i,ml&x){long long t;i>>t;x=t;return i;} void main(); } int main(){my::main();} namespace my{ #define eb emplace_back #define all(a) (a).begin(),(a).end() #define RD(T,...) T __VA_ARGS__;li(__VA_ARGS__) #define LL(...) RD(ll,__VA_ARGS__) #define JO(a,b) a##b #define jo(a,b) JO(a,b) #define usymbol(a) jo(a,__LINE__) #define FE(v,e,...) for(au&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):v) #define FO(n) for(ll usymbol(i)=n;usymbol(i)-->0;) #define FOR(i,...) for(au[i,i##O,i##E]=rng(0,__VA_ARGS__);i<i##O;i+=i##E) #define fe(v,...) FE(v,__VA_ARGS__) #define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__)) #define of(i,...) for(au[i,i##O,i##E]=rng(1,__VA_ARGS__);i>=i##O;i-=i##E) #define I template #define J class #define au auto #define rr return using namespace std; using vo=void;using bo=bool; vo solve(); I<J A,J B>constexpr bo same=is_same_v<A,B>; using is=istream;using os=ostream; using dd=long double;using ll=long long;using ull=unsigned long long; using lll=__int128_t;using ulll=__uint128_t;using str=string; os&operator<<(os&o,const ulll&x){rr(x<10?o:o<<x/10)<<ll(x%10);} os&operator<<(os&o,const lll&x){rr o<<str(x<0,'-')<<ulll(x>0?x:-x);} constexpr dd ee=1e-12; constexpr ll oo=3e18; constexpr ll dx[]{-1,0,1,0,-1,1,1,-1},dy[]{0,-1,0,1,-1,-1,1,1}; constexpr char sp=32,nl=10; au rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,(s?b:a)=0;rr tuple{a-s,b,c};} I<J T>T zz(T x){rr x<0?-x:x;} I<J T>ll len(const T&a){rr a.size();} I<J T>bo amax(T&a,const T&b){rr a<b?a=b,1:0;} I<J...A>au max(const A&...a){rr max(initializer_list<common_type_t<A...>>{a...});} I<J...A>au min(const A&...a){rr min(initializer_list<common_type_t<A...>>{a...});} I<J A,J B=A>struct cp{ A a={};B b={}; cp(){} cp(A a,B b):a(a),b(b){} cp(pair<A,B>p):a(p.first),b(p.second){} bo operator==(const cp&c)const{rr a==c.a&&b==c.b;} au operator<=>(const cp&c)const{rr a!=c.a?a<=>c.a:b<=>c.b;} friend is&operator>>(is&i,cp&c){rr i>>c.a>>c.b;} friend os&operator<<(os&o,const cp&c){rr o<<c.a<<sp<<c.b;} };using cl=cp<ll>; I<J A,J B=A,J C=A>struct tr{ A a={};B b={};C c={}; tr(){} tr(A a,B b,C c):a(a),b(b),c(c){} bo operator==(const tr&t)const{rr a==t.a&&b==t.b&&c==t.c;} au operator<=>(const tr&t)const{rr a!=t.a?a<=>t.a:b!=t.b?b<=>t.b:c<=>t.c;} friend is&operator>>(is&i,tr&t){rr i>>t.a>>t.b>>t.c;} friend os&operator<<(os&o,const tr&t){rr o<<t.a<<sp<<t.b<<sp<<t.c;} };using tl=tr<ll>; I<J T,size_t n>using ar=array<T,n>; I<J T,size_t n>os&operator<<(os&o,const ar<T,n>&a){fo(i,n)o<<a[i]<<str(i!=n-1,sp);rr o;} I<J T,J U=T>using map=std::map<T,U>; I<J T,J U>os&operator<<(os&o,const map<T,U>&m){fe(m,e)o<<e.first<<sp<<e.second<<nl;rr o;} I<J T,J U=T>using umap=unordered_map<T,U>; I<J T,J U>os&operator<<(os&o,const umap<T,U>&m){fe(m,e)o<<e.first<<sp<<e.second<<nl;rr o;} I<size_t n>using bset=bitset<n>; I<size_t n>os&operator<<(os&o,const bset<n>&b){fo(i,n)o<<b[i];rr o;} I<J...A>os&operator<<(os&o,const tuple<A...>&t){apply([&](const au&...a){ll i=sizeof...(a);(((o<<a<<str(--i>0,sp))),...);},t);rr o;} I<J T,J F>struct prique:priority_queue<T,vector<T>,F>{ prique(const initializer_list<T>&a={}){fe(a,e)this->emplace(e);} prique(const vector<T>&a){fe(a,e)this->emplace(e);} friend T bg(prique&q){rr q.top();} friend T pot(prique&q){T r=q.top();q.pop();rr r;} friend os&operator<<(os&o,prique q){while(len(q))o<<pot(q)<<str(len(q)>0,sp);rr o;} }; I<J T>using qmax=prique<T,less<>>; I<J T>using qmin=prique<T,greater<>>; I<J T>struct mset:multiset<T>{ mset(const initializer_list<T>&a={}){fe(a,e)this->emplace(e);} mset(const vector<T>&a){fe(a,e)this->emplace(e);} friend os&operator<<(os&o,const mset&s){fe(s,e)o<<e<<str(&e!=&*s.rbegin(),sp);rr o;} }; I<J T>struct set:mset<T>{ set(const initializer_list<T>&a={}){fe(a,e)this->emplace(e);} set(const vector<T>&a){fe(a,e)this->emplace(e);} I<J...A>au emplace(A&&...a){ T x(std::forward<A>(a)...); if(au p=this->find(x);p!=this->end())rr pair{p,0}; rr pair{this->mset<T>::emplace(x),1}; } }; I<J V>struct ve; I<J V>constexpr bo isv=0; I<J V>constexpr bo isv<ve<V>> =1; I<J V>constexpr bo isv<vector<V>> =1; I<J V>au rawv(V){if constexpr(isv<V>)rr rawv(V(1)[0]);else rr V();} I<J V>struct ve:vector<V>{ using vector<V>::vector; using T=decltype(rawv(V())); I<J U>ve(const vector<U>&v={}){static_assert(isv<V> ==isv<U>);fe(v,e)this->eb(e);} ve&operator+=(const ve&u){au&v=*this;fo(i,len(v))v[i]+=u[i];rr v;}ve operator+(const ve&u)const{rr ve(*this)+=u;} ve&operator-=(const ve&u){au&v=*this;fo(i,len(v))v[i]-=u[i];rr v;}ve operator-(const ve&u)const{rr ve(*this)-=u;} ve&operator^=(const ve&u){fe(u,e)this->eb(e);rr*this;}ve operator^(const ve&u)const{rr ve(*this)^=u;} ve&operator+=(const T&x){au&v=*this;fe(v,e)e+=x;rr v;}ve operator+(const T&x)const{rr ve(*this)+=x;} ve&operator-=(const T&x){au&v=*this;fe(v,e)e-=x;rr v;}ve operator-(const T&x)const{rr ve(*this)-=x;} ve&operator*=(const T&x){au&v=*this;fe(v,e)e*=x;rr v;}ve operator*(const T&x)const{rr ve(*this)*=x;} ve&operator++(){rr*this+=1;} ve&operator--(){rr*this-=1;} ve operator-()const{rr ve(*this)*=-1;} I<size_t n>au&operator+=(const bset<n>&a){fo(i,n)(*this)[i]+=a[i];rr*this;} I<size_t n>au&operator-=(const bset<n>&a){fo(i,n)(*this)[i]-=a[i];rr*this;} au lower_bound(const V&x)const{rr std::lower_bound(all(*this),x);} au upper_bound(const V&x)const{rr std::upper_bound(all(*this),x);} I<J F>au scan(F f)const{cp<T,bo>r;fe(*this,e)if constexpr(!isv<V>)r.b?f(r.a,e),r:r={e,1};else if(au s=e.scan(f);s.b)r.b?f(r.a,s.a),r:r=s;rr r;} T max()const{rr scan([](T&a,const T&b){a<b?a=b:0;}).a;} T min()const{rr scan([](T&a,const T&b){a>b?a=b:0;;}).a;} friend is&operator>>(is&i,ve&v){fe(v,e)i>>e;rr i;} friend os&operator<<(os&o,const ve&v){fe(v,e)o<<e<<str(&e!=&v.back(),isv<V>?nl:sp);rr o;} }; I<J T=ll,size_t n,size_t i=0>au vec(const ll(&s)[n],T x={}){if constexpr(n==i+1)rr ve<T>(s[i],x);else{au X=vec<T,n,i+1>(s,x);rr ve<decltype(X)>(s[i],X);}} I<ll n,J...A>vo setsize(const ll(&l)[n],A&...a){((a=vec(l,rawv(a))),...);} I<J T>using v2=ve<ve<T>>;using u1=ve<ll>;using u2=v2<ll>; using graph=v2<cl>; vo io(){cin.tie(0)->sync_with_stdio(0);cout<<fixed<<setprecision(15);cerr<<nl;} I<J...A>vo li(A&...a){(cin>>...>>a);} I<J...A>vo vi(A&...a){fo(i,(len(a)&...))(cin>>...>>a[i]);} I<char c=sp,J...A>vo pp(const A&...a){ll i=sizeof...(a);((cout<<a<<str(--i>0,c)),...);cout<<nl;} u1 it(ll n,ll x=0){u1 a;fo(i,n)a.eb(i+x);rr a;} I<J F,J...A>u1 vsrt(F f,A&...a){u1 o=it((len(a)&...));sort(all(o),f);([&](au&e){au c=e;fo(i,len(e))e[i]=c[o[i]];}(a),...);rr o;} I<J F>struct rec:F{rec(F&&f):F(std::forward<F>(f)){}I<J...A>decltype(au)operator()(A&&...a)const{rr F::operator()(*this,std::forward<A>(a)...);}}; namespace cht{ template<class T>struct line{ T a={},b={}; line(){} line(T a,T b):a(a),b(b){} bo operator<(const line&rhs)const{ return a!=rhs.a?a>rhs.a:b<rhs.b; } friend os&operator<<(os&o,const line&l){ return o<<l.a<<sp<<l.b; } }; template<class T>struct crosspoint{ T n,d; line<T>l; crosspoint(T n,T d,const line<T>&l):n(n),d(d),l(l){ if(this->d<0)this->n*=-1,this->d*=-1; } bo operator<(const crosspoint&rhs)const{ return n*rhs.d<rhs.n*d; } friend os&operator<<(os&o,const crosspoint&p){ return o<<p.n<<sp<<p.d<<sp<<p.l; } }; template<class T>crosspoint<T>calc_crosspoint(const line<T>&l1,const line<T>&l2){ return{l1.b-l2.b,l2.a-l1.a,l1}; } template<class T>bo need(const line<T>&l1,const line<T>&l2,const line<T>&l3){ if(l1.a==l2.a&&l1.b<=l2.b)return 0; return(l2.a-l1.a)*(l3.b-l2.b)<(l2.b-l1.b)*(l3.a-l2.a); } template<class T>struct min_convex_hull_trick{ set<line<T>>ls; set<crosspoint<T>>ps; vo add(T a,T b){ line l(a,b); auto lp=ls.emplace(a,b).first; if(lp!=ls.begin()&&lp!=prev(ls.end())){ if(need(*prev(lp),*lp,*next(lp))){ ps.erase(calc_crosspoint(*prev(lp),*next(lp))); }else{ ls.erase(lp); return; } } typename set<line<T>>::iterator cu; if(lp!=ls.begin()){ cu=prev(lp); while(cu!=ls.begin()&&!need(*prev(cu),*cu,l)){ ps.erase(calc_crosspoint(*prev(cu),*cu)); cu=prev(cu); } ls.erase(next(cu),lp); lp=ls.find(l); ps.emplace(calc_crosspoint(*prev(lp),*lp)); } if(lp!=prev(ls.end())){ cu=next(lp); while(cu!=prev(ls.end())&&!need(l,*cu,*next(cu))){ ps.erase(calc_crosspoint(*cu,*next(cu))); cu=next(cu); } ls.erase(next(lp),cu); lp=ls.find(l); ps.emplace(calc_crosspoint(*lp,*next(lp))); } } T operator()(T x){ auto p=ps.lower_bound(crosspoint<T>(x,1,line<T>())); if(p!=ps.end())return p->l.a*x+p->l.b; else return ls.rbegin()->a*x+ls.rbegin()->b; } }; template<class T>struct max_convex_hull_trick:min_convex_hull_trick<T>{ using base=min_convex_hull_trick<T>; vo add(T a,T b){base::add(-a,-b);} T operator()(T x){return-base::operator()(x);} }; } vo main(){io();ll T=1;fo(T)solve();} template<class T>ll sgn(const T&a){return(a>=ee)-(a<=-ee);} template<class T,class U>ll sgn(const T&a,const U&b){return sgn(a-b);} vo solve(){ LL(N); ve<dd>a(N),b(N);vi(a,b); vsrt([&](ll i,ll j){rr sgn(b[i],b[j])?sgn(b[i],b[j])<0:sgn(a[i],a[j])<0;},a,b); cht::min_convex_hull_trick<dd>cht_min; cht::max_convex_hull_trick<dd>cht_max; fo(i,N)cht_min.add(-b[i],a[i]); of(i,N)cht_max.add(b[i],-a[i]); dd ans=0; dd t=0; fo(i,N){ if(b[i]){ amax(ans,zz(b[i]*cht_max(a[i]/b[i]))); amax(ans,zz(b[i]*cht_min(a[i]/b[i]))); }else{ amax(t,zz(a[i])); } } fo(i,N)b[i]=zz(b[i]); amax(ans,t*b.max()); pp(llroundl(ans)); }}