結果
問題 | No.1826 Fruits Collecting |
ユーザー | eQe |
提出日時 | 2023-07-30 16:36:27 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 12,996 bytes |
コンパイル時間 | 8,014 ms |
コンパイル使用メモリ | 334,352 KB |
実行使用メモリ | 36,644 KB |
最終ジャッジ日時 | 2024-10-09 11:49:30 |
合計ジャッジ時間 | 16,981 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,816 KB |
testcase_01 | AC | 5 ms
6,816 KB |
testcase_02 | AC | 4 ms
6,820 KB |
testcase_03 | AC | 6 ms
6,820 KB |
testcase_04 | AC | 4 ms
6,820 KB |
testcase_05 | AC | 139 ms
17,516 KB |
testcase_06 | AC | 209 ms
28,052 KB |
testcase_07 | AC | 140 ms
19,252 KB |
testcase_08 | AC | 14 ms
5,248 KB |
testcase_09 | AC | 206 ms
23,764 KB |
testcase_10 | AC | 133 ms
18,448 KB |
testcase_11 | AC | 143 ms
18,268 KB |
testcase_12 | AC | 46 ms
9,708 KB |
testcase_13 | AC | 22 ms
6,680 KB |
testcase_14 | AC | 36 ms
7,908 KB |
testcase_15 | AC | 322 ms
36,512 KB |
testcase_16 | AC | 331 ms
36,512 KB |
testcase_17 | AC | 329 ms
36,644 KB |
testcase_18 | AC | 329 ms
36,512 KB |
testcase_19 | AC | 331 ms
36,516 KB |
testcase_20 | AC | 334 ms
36,512 KB |
testcase_21 | AC | 330 ms
36,384 KB |
testcase_22 | AC | 328 ms
36,384 KB |
testcase_23 | AC | 327 ms
36,640 KB |
testcase_24 | AC | 323 ms
36,512 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 58 ms
10,880 KB |
testcase_31 | AC | 121 ms
18,396 KB |
testcase_32 | AC | 57 ms
10,756 KB |
testcase_33 | AC | 227 ms
28,552 KB |
testcase_34 | AC | 187 ms
21,804 KB |
testcase_35 | AC | 35 ms
7,796 KB |
testcase_36 | AC | 225 ms
28,244 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 2 ms
5,248 KB |
testcase_44 | AC | 2 ms
5,248 KB |
testcase_45 | AC | 2 ms
5,248 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace atcoder; template<typename V>struct ve; using ml=modint;using m1=ve<ml>; auto&operator>>(std::istream&i,ml&x){long long t;i>>t;x=t;return i;} auto&operator<<(std::ostream&o,const ml&x){return o<<x.val();} #define ep emplace #define eb emplace_back #define all(a) begin(a),end(a) #define wh(...) while(__VA_ARGS__) #define ef(...) else if(__VA_ARGS__) #define done(...) rr pp(__VA_ARGS__) #define LL(...) RD(ll,__VA_ARGS__) #define ST(...) RD(str,__VA_ARGS__) #define RD(T,...) T __VA_ARGS__;li(__VA_ARGS__) #define UL(n,...) u1 __VA_ARGS__;setsize({n},__VA_ARGS__);li(__VA_ARGS__) #define UV(n,...) u1 __VA_ARGS__;setsize({n},__VA_ARGS__);vi(__VA_ARGS__) #define U2(n,m,...) u2 __VA_ARGS__;setsize({n,m},__VA_ARGS__);li(__VA_ARGS__) #define FE(v,e,...) for(au&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):v) #define FO(n) for(ll jo(i,__LINE__)=n;jo(i,__LINE__)-->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##O,i,i##E]=rng(1,__VA_ARGS__);i>=i##O;i-=i##E) #define debug(...) pp(#__VA_ARGS__,__VA_ARGS__) #define JO(s,t) s##t #define jo(s,t) JO(s,t) #define I(...) template<__VA_ARGS__> #define J typename #define O operator #define au auto #define cs const #define ifc if constexpr #define rr return #define uu using uu std::cin,std::cout,std::begin,std::end,std::rbegin; uu std::deque,std::tuple,std::array,std::bitset; uu std::swap,std::move,std::minmax,std::gcd,std::lcm; I(J T)uu ilis=std::initializer_list<T>; uu vo=void; vo solve(); uu bo=bool; I(J A,J B)constexpr bo same=std::is_same_v<A,B>; I(bo b,J A,J B)uu ift=std::conditional_t<b,A,B>; uu is=std::istream;uu os=std::ostream; uu dd=long double;uu ll=long long; uu ull=unsigned long long; uu lll=__int128_t;uu ulll=__uint128_t; uu str=std::string; ll oo=3e18,i998244353=998244353,i1000000007=1000000007; array<ll,8>dx{-1,0,1,0,-1,1,1,-1},dy{0,-1,0,1,-1,-1,1,1}; dd ee=1e-12,pi=acosl(-1); str sp=" ",nc="",nl="\n"; I(J T,J U=T)uu map=std::map<T,U>; I(J T,J U=T)uu umap=std::unordered_map<T,U>; I(J T)uu qmax=std::priority_queue<T>; I(J T)uu qmin=std::priority_queue<T,std::vector<T>,std::greater<>>; I(J T,ll n)au TP(){ifc(n)rr tuple_cat(tuple(T()),TP<T,n-1>());else rr tuple();} I(J T,ll n)uu tp=decltype(TP<T,n>());I(ll n)uu tpl=tp<ll,n>; tpl<3>rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,a=0;rr{a,b-s,c};} ll rnd(ll l,ll r=oo){static ull a=76,b=53,c=20,d=41;ull t=a^(a<<11);a=b,b=c,c=d,d=(d^(d>>19))^(t^(t>>8));rr r==oo?d%l:d%(r-l)+l;} bo odd(ll x){rr x&1;}bo eve(ll x){rr~x&1;} ll pwm1(ll x){rr 1-2*(x&1);}ll pw2(ll n){rr 1LL<<n;} I(J T)bo at(T x,ll i){rr x>>i&1;} ll l2(ulll x){x|=1;ll r=0;wh(x)x>>=1,++r;rr r;} ll l10(ulll x){x|=1;ll r=0;wh(x)x/=10,++r;rr r;} I(J T,J U,J V)bo in(T l,U x,V r){rr l<=x&&x<r;} I(J T)T flo(T x,T y){rr y<0?x=-x,y=-y:x>=0?x/y:(x+1)/y-1;} I(J T)T cei(T x,T y){rr y<0?x=-x,y=-y:x<=0?x/y:(x-1)/y+1;} I(J T)T sq(T a){rr a*a;} I(J T)T zz(T x){rr x<0?-x:x;} I(J T)ll len(cs T&a){rr a.size();} I(J T)bo add(T&a,cs T&b){rr a+=b,1;} I(J T,J U)bo amax(T&a,cs U&b){rr a<b?a=b,1:0;} I(J T,J U)bo amin(T&a,cs U&b){rr a>b?a=b,1:0;} struct edg{ll t,w;edg(){}edg(ll t,ll w=1):t(t),w(w){}}; I(J A,J B=A)struct cp{ A a={};B b={}; cp(){} cp(A a,B b):a(a),b(b){} cp(std::pair<A,B>p):a(p.first),b(p.second){} cp O-()cs{rr cp(-a,-b);} cp&O+=(cs cp&c){a+=c.a,b+=c.b;rr*this;}cp O+(cs cp&c)cs{rr cp{*this}+=c;} cp&O-=(cs cp&c){a-=c.a,b-=c.b;rr*this;}cp O-(cs cp&c)cs{rr cp{*this}-=c;} bo O<(cs cp&c)cs{rr a!=c.a?a<c.a:b<c.b;} bo O>(cs cp&c)cs{rr a!=c.a?a>c.a:b>c.b;} bo O==(cs cp&c)cs{rr a==c.a&&b==c.b;} };uu 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 O<(cs tr&t)cs{rr a!=t.a?a<t.a:b!=t.b?b<t.b:c<t.c;} bo O>(cs tr&t)cs{rr a!=t.a?a>t.a:b!=t.b?b>t.b:c>t.c;} };uu tl=tr<ll>; 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<std::vector<V>> =1; I(J V)au pure_val(V){ifc(isv<V>)rr pure_val(J V::value_type());else rr V();} I(J V)struct ve:std::vector<V>{ uu std::vector<V>::vector; uu pure_type=decltype(pure_val(V())); ve(cs std::vector<V>&v={}){fe(v,e)this->eb(e);} au&O+=(cs ve&u){au&v=*this;fo(i,len(v))v[i]+=u[i];rr v;} au&O-=(cs ve&u){au&v=*this;fo(i,len(v))v[i]-=u[i];rr v;} au&O^=(cs ve&u){fe(u,e)this->eb(e);rr*this;} au&O+=(cs pure_type&c){au&v=*this;fe(v,e)e+=c;rr v;} au&O-=(cs pure_type&c){au&v=*this;fe(v,e)e-=c;rr v;} au O+(cs ve&u){rr ve(*this)+=u;} au O-(cs ve&u){rr ve(*this)-=u;} au O^(cs ve&u){rr ve(*this)^=u;} au O-(){ve r=*this;fe(r,e)e=-e;rr r;} au O+(cs pure_type&c){rr ve(*this)+=c;}au&O++(){rr*this+=1;} au O-(cs pure_type&c){rr ve(*this)-=c;}au&O--(){rr*this-=1;} au lower_bound(cs V&x){rr std::lower_bound(all(*this),x);} au upper_bound(cs V&x){rr std::upper_bound(all(*this),x);} ll arglb(cs V&x){rr lower_bound(x)-begin(*this);} ll argub(cs V&x){rr upper_bound(x)-begin(*this);} ll argmax(){rr std::max_element(all(*this))-begin(*this);} ll argmin(){rr std::min_element(all(*this))-begin(*this);} au ika_max(cs V&x){au p=this->upper_bound(x);rr p!=this->begin()?prev(p):this->end();} au ijo_min(cs V&x){rr this->lower_bound(x);} vo af(V e={}){this->ep(begin(*this),e);} vo df(){this->erase(begin(*this));} I(bo f(pure_type&,cs pure_type&))au scan(){ cp<pure_type,bo>r; fe(*this,e){ ifc(!isv<V>)r.b?f(r.a,e),r:r={e,1}; ef(au t=e.template scan<f>();t.b)r.b?f(r.a,t.a),r:r=t; } rr r; } au sum(){rr scan<add>().a;} au max(){rr scan<amax>().a;} au min(){rr scan<amin>().a;} vo fill(pure_type x={}){fe(*this,e)ifc(isv<V>)e.fill(x);else e=x;} au zeta(){ve v=*this;ifc(isv<V>)fe(v,e)e=e.zeta();fo(i,len(v)-1)v[i+1]+=v[i];rr v;} au mobi(){ve v=*this;ifc(isv<V>)fe(v,e)e=e.mobi();of(i,len(v)-1)v[i+1]-=v[i];rr v;} au de(cs str&b="a"){ ift<isv<V>,ve<str>,str>r; ifc(isv<V>)fe(*this,e)r.eb(e.de(b)); else fe(*this,e)r+=len(b)==1?e+b[0]:0<=e&&e<len(b)?b[e]:'|'; rr r; } }; I(J T=ll,ll n,ll i=0)au vec(cs ll(&s)[n],T x={}){ ifc(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(cs ll(&l)[n],A&...a){((a=vec(l,pure_val(a))),...);} I(J T)uu V1=ve<T>;uu u1=V1<ll>;I(J T)uu V2=V1<V1<T>>;uu u2=V2<ll>; uu cls=V1<cl>;uu tls=V1<tl>;uu strs=V1<str>;uu gra=V2<edg>; I(J T)struct set:std::set<T>{ set(cs V1<T>&a={}){fe(a,e)this->ep(e);} au ika_max(cs T&x){au p=this->upper_bound(x);rr p!=this->begin()?prev(p):this->end();} au ijo_min(cs T&x){rr this->lower_bound(x);} au between(cs T&l,cs T&r){au p=this->lower_bound(l),q=this->lower_bound(r);rr cp{p,q};} friend os&O<<(os&o,cs set&s){fe(s,e)o<<e<<(&e!=&rb(s)?sp:nc);rr o;} }; I(J T)struct mset:std::multiset<T>{ mset(cs V1<T>&a={}){fe(a,e)this->ep(e);} vo uerase(cs T&x){if(au p=this->find(x);p!=this->end())this->erase(p);} au ika_max(cs T&x){au p=this->upper_bound(x);rr p!=this->begin()?prev(p):this->end();} au ijo_min(cs T&x){rr this->lower_bound(x);} au between(cs T&l,cs T&r){au p=this->lower_bound(l),q=this->lower_bound(r);rr cp{p,q};} friend os&O<<(os&o,cs mset&s){fe(s,e)o<<e<<(&e!=&rb(s)?sp:nc);rr o;} }; I(J T)struct uset:std::unordered_set<T>{ uset(cs V1<T>&a={}){fe(a,e)this->ep(e);} friend os&O<<(os&o,cs uset&s){fe(s,e)o<<e<<(&e!=&rb(s)?sp:nc);rr o;} }; I(J T)T pof(set<T>&s){T r=bg(s);s.erase(begin(s));rr r;} I(J T)T pof(mset<T>&s){T r=bg(s);s.erase(begin(s));rr r;} I(J T)T pob(set<T>&s){T r=rb(s);s.erase(--end(s));rr r;} I(J T)T pob(mset<T>&s){T r=rb(s);s.erase(--end(s));rr r;} I(J T)T&srt(T&a){sort(all(a));rr a;} I(J T)T&rv(T&a){reverse(all(a));rr a;} I(J T)T&rsr(T&a){rr rv(srt(a));} I(J T)T&uq(T&a){srt(a).erase(unique(all(a)),end(a));rr a;} I(J T)decltype(au)bg(T&a){rr*begin(a);} I(J T)decltype(au)rb(T&a){rr*rbegin(a);} I(J T)au pof(T&a){au r=bg(a);a.pop_front();rr r;} I(J T)au pob(T&a){au r=rb(a);a.pop_back();rr r;} I(J T)au pot(T&a){au r=a.top();a.pop();rr r;} I(J...A)au max(cs A&...a){rr max(ilis<std::common_type_t<A...>>{a...});} I(J...A)au min(cs A&...a){rr min(ilis<std::common_type_t<A...>>{a...});} struct fio{fio(){cin.tie(0)->sync_with_stdio(0); cout<<std::fixed<<std::setprecision(15);std::cerr<<"ok"<<nl;}}fio; os&O<<(os&o,cs ulll&x){rr(x<10?o:o<<x/10)<<ll(x%10);} os&O<<(os&o,cs lll&x){rr o<<(x<0?"-":nc)<<ulll(zz(x));} os&O<<(os&o,cs edg&e){rr o<<e.t<<sp<<e.w;} I(J T)os&O<<(os&o,cs deque<T>&v){fe(v,e)o<<e<<sp;rr o;} I(J T,J U)os&O<<(os&o,cs cp<T,U>&c){rr o<<c.a<<sp<<c.b;} I(J T,J U)os&O<<(os&o,cs map<T,U>&m){fe(m,e)o<<cp(e)<<nl;rr o;} I(J...A)os&O<<(os&o,cs tuple<A...>&t){apply([&](cs au&...a){ll i=0;(((o<<a<<(++i!=sizeof...(a)?sp:nc))),...);},t);rr o;} I(J V)is&O>>(is&i,std::vector<V>&v){fe(v,e)i>>e;rr i;} I(J V)os&O<<(os&o,cs std::vector<V>&v){ str s=nl; ifc(!isv<V>)s=sp;else ifc(isv<J V::value_type>)s+=nl; fe(v,e)o<<e<<(&e!=&rb(v)?s:nc); rr o; } I(J...A)vo pp(cs A&...a){ll i=0;((cout<<a<<(++i!=sizeof...(a)?sp:nc)),...);cout<<nl;} I(J...A)vo li(A&...a){(cin>>...>>a);} I(J...A)vo vi(A&...a){fo(i,(len(a)&...))(cin>>...>>a[i]);} vo Yes(bo y=1){pp(y?"Yes":"No");}vo No(){Yes(0);} gra tog(cs u2&a){gra g;fe(a,e){g.eb();fe(e,v)rb(g).eb(v);}rr g;} u2 tou(cs gra&g){u2 a;fe(g,e){a.eb();fe(e,v,w)rb(a).eb(v);}rr a;} au gi(gra&g,ll m,bo y=0,bo f=0){UV(m,a,b,c);a-=!f,b-=!f;fo(i,m)g[a[i]].eb(b[i],c[i]),!y?g[b[i]].eb(a[i],c[i]),0:0;rr tuple{a,b,c};} au gi(u2&g,ll m,bo y=0,bo f=0){UV(m,a,b);a-=!f,b-=!f;fo(i,m)g[a[i]].eb(b[i]),!y?g[b[i]].eb(a[i]):0;rr tuple{a,b};} I(J G)au ti(G&g,bo y=0,bo f=0){rr gi(g,len(g)-1,y,f);} u1 en(cs str&s,cs str&b="a"){u1 r;fe(s,e)r.eb(len(b)==1?e-b[0]:b.find_first_of(e));rr r;} u1 sien(cs str&b="a"){ST(s);rr en(s,b);} u2 en(cs strs&s,cs str&b="a"){u2 r;fe(s,e)r.eb(en(e,b));rr r;} u2 sien(ll n,cs str&b="a"){u2 r;fo(n)r.eb(sien(b));rr r;} I(J F)struct rec:F{rec(F&&f):F(std::forward<F>(f)){}I(J...A)decltype(au)O()(A&&...a)cs{rr F::O()(*this,std::forward<A>(a)...);}}; I(J...A)vo dec(A&...a){((--a),...);} u1 it(ll n,ll x=0){u1 a;fo(i,n)a.eb(i+x);rr a;} I(J...A)u1 zp(A&...a){u1 v=(a^...);uq(v);([&](u1&u){fe(u,e)e=v.arglb(e);}(a),...);rr v;} I(J F,J...A)u1 vs(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)dd bsd(F f,dd o,dd n){fo(log2(zz(o-n)/ee)+5)(f((o+n)/2)?o:n)=(o+n)/2;rr o;} I(J F)ll bsl(F f,ll o,ll n){wh(zz(o-n)>1)(f((o+n)/2)?o:n)=(o+n)/2;rr o;} ll sqr(ll x){ll r=sqrt(zz(x-ee));wh(r+1<=x/(r+1))++r;rr r;} u1 divs(ll n){u1 r;fo(i,1,sqr(n)+1)if(n%i==0)r.eb(i),r.eb(n/i);rr uq(r);} cls fact(ll n){umap<ll>m;fo(i,2,sqr(n)+1)wh(n%i==0)++m[i],n/=i;if(n>1)++m[n];cls r;fe(m,e)r.eb(e);rr srt(r);} cls rle(cs u1&a){cls r;fe(a,e)len(r)&&e==rb(r).a?++rb(r).b:r.eb(e,1).b;rr r;} cls rce(u1 a){rr rle(srt(a));} lll pow(lll x,lll n,ll m=0){lll r=1;wh(n)n&1?r*=x:r,x*=x,m?r%=m,x%=m:r,n>>=1;rr r;} int main(){ll T=1;fo(T)solve();} I(J T)T fill(ll x){ ifc(same<T,ll>)rr x; else ifc(same<T,cl>)rr T(x,x); else ifc(same<T,tl>)rr T(x,x,x); else ifc(same<T,array<ll,T().size()>>){T r;fe(r,e)e=x;rr r;} else ifc(same<T,tpl<std::tuple_size_v<T>>>){ T r;apply([&](au&...a){((a=x),...);},r);rr r; }else assert(0); } I(J T)T moo(){rr fill<T>(-oo);} I(J T)T poo(){rr fill<T>(oo);} I(J T)T uni(){rr{};} I(J T)T op_max(T a,T b){rr max(a,b);} I(J T)T op_min(T a,T b){rr min(a,b);} I(J T)T op_sum(T a,T b){rr a+b;} I(J T)T op_mul(T a,T b){rr a*b;} I(J T)uu seg_max=segtree<T,op_max<T>,moo<T>>; I(J T)uu seg_min=segtree<T,op_min<T>,poo<T>>; I(J T)uu seg_sum=segtree<T,op_sum<T>,uni<T>>; I(J S)ll kth_on_segtree(seg_sum<S>&s,ll k,ll l=0){ rr s.max_right(l,[&](S v){rr v<k;}); } I(J S)ll ika_leftmost(seg_min<S>&s,ll x,ll l){ rr s.max_right(l,[&](S v){rr v>x;}); } I(J S)ll ika_righmost(seg_min<S>&s,ll x,ll r){ rr s.min_left(r,[&](S v){rr v>x;})-1; } I(J S)ll ijo_leftmost(seg_max<S>&s,ll x,ll l){ rr s.max_right(l,[&](S v){rr v<x;}); } I(J S)ll ijo_righmost(seg_max<S>&s,ll x,ll r){ rr s.min_left(r,[&](S v){rr v<x;})-1; } cp<u1>rot45(cs u1&x,cs u1&y){ ll n=len(x); u1 u(n),v(n); fo(i,n){ u[i]=x[i]-y[i]; v[i]=x[i]+y[i]; } rr cp{u,v}; } bo issquare(cs u1&x,cs u1&y){ ll n=4; u1 v; fo(i,n)fo(j,i+1,n)v.eb(sq(x[i]-x[j])+sq(y[i]-y[j])); srt(v); ll a=bg(v); if(a==0)rr 0; rr v[0]==a&&v[3]==a&&v[4]==a*2&&v[5]==a*2; } bo iscube(cs u1&x,cs u1&y,cs u1&z){ ll n=8; u1 v; fo(i,n)fo(j,i+1,n)v.eb(sq(x[i]-x[j])+sq(y[i]-y[j])+sq(z[i]-z[j])); srt(v); ll a=bg(v); if(a==0)rr 0; rr v[0]==a&&v[11]==a&&v[12]==a*2&&v[23]==a*2&&v[24]==a*3&&v[27]==a*3; } vo solve(){ LL(N); UV(N,t,x,v); t.eb(),x.eb(),v.eb(); u1 a=x+t,b=-x+t; ll M=len(zp(a,b)); seg_max<ll>s(M); s.set(a[N],0); u2 g(M); fo(i,N)g[a[i]].eb(i); u1 res(N); fo(k,a[N],M){ fe(g[k],i)res[i]=s.prod(0,b[i]+1)+v[i]; fe(g[k],i)s.set(b[i],max(s.get(b[i]),res[i])); } pp(res.max()); }