結果

問題 No.2221 Set X
ユーザー eQeeQe
提出日時 2023-08-03 01:43:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 12,001 bytes
コンパイル時間 6,656 ms
コンパイル使用メモリ 335,996 KB
実行使用メモリ 235,632 KB
最終ジャッジ日時 2024-10-12 23:48:08
合計ジャッジ時間 16,866 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,636 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,820 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 2 ms
6,816 KB
testcase_05 AC 2 ms
6,816 KB
testcase_06 AC 2 ms
6,820 KB
testcase_07 AC 3 ms
6,820 KB
testcase_08 AC 4 ms
6,816 KB
testcase_09 AC 2 ms
6,816 KB
testcase_10 AC 5 ms
6,816 KB
testcase_11 AC 3 ms
6,820 KB
testcase_12 AC 4 ms
6,820 KB
testcase_13 AC 4 ms
6,816 KB
testcase_14 AC 8 ms
6,820 KB
testcase_15 AC 4 ms
6,820 KB
testcase_16 AC 1,547 ms
194,192 KB
testcase_17 AC 358 ms
51,576 KB
testcase_18 AC 1,928 ms
235,632 KB
testcase_19 AC 296 ms
43,896 KB
testcase_20 AC 895 ms
111,188 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 VE(a,...) au a=vec(__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 fs(i,...) for(ll i##E=__VA_ARGS__,i=i##E;i;--i&=i##E)
#define debug(...) pp(#__VA_ARGS__,__VA_ARGS__)
#define JO(a,b) a##b
#define jo(a,b) JO(a,b)
#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,std::get;
uu std::swap,std::move,std::gcd,std::lcm,std::prev,std::next;
uu std::deque,std::tuple,std::array,std::bitset,std::minmax;
I(J T)uu ilis=std::initializer_list<T>;
uu vo=void;uu bo=bool;
vo solve();
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;
dd ee=1e-12,pi=acosl(-1);
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};
char sp=32,nl=10;au Yes(bo y){rr y?"Yes":"No";}au No(){rr Yes(0);}
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>;
au rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,a=0;rr tuple{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;}
ll ppc(ll x){rr __builtin_popcountll(x);}
ll msb(ll x){rr x?63-__builtin_clzll(x):-1;}
ll lsb(ll x){rr x?__builtin_ctzll(x):-1;}
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;}
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 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 raw_val(V){ifc(isv<V>)rr raw_val(V(1)[0]);else rr V();}

I(J V)struct ve:std::vector<V>{
  uu std::vector<V>::vector;
  uu raw_type=decltype(raw_val(V()));
  I(J U)ve(cs std::vector<U>&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 raw_type&c){au&v=*this;fe(v,e)e+=c;rr v;}
  au&O-=(cs raw_type&c){au&v=*this;fe(v,e)e-=c;rr v;}
  au&O*=(cs raw_type&c){au&v=*this;fe(v,e)e*=c;rr v;}
  I(size_t n)au&O+=(cs bitset<n>&a){fo(i,len(*this))(*this)[i]+=a[i];rr*this;}
  I(size_t n)au&O-=(cs bitset<n>&a){fo(i,len(*this))(*this)[i]-=a[i];rr*this;}

  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+(cs raw_type&c){rr ve(*this)+=c;}au&O++(){rr*this+=1;}
  au O-(cs raw_type&c){rr ve(*this)-=c;}au&O--(){rr*this-=1;}
  au O*(cs raw_type&c){rr ve(*this)*=c;}au O-(){rr ve(*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);}
  au slice(ll l,ll r){rr ve(begin(*this)+l,begin(*this)+r);}
  vo af(V e={}){this->ep(begin(*this),e);}
  vo df(){this->erase(begin(*this));}

  I(bo f(raw_type&,cs raw_type&))au scan(){
    cp<raw_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;
  }
  raw_type sum(){rr scan<add>().a;}
  raw_type max(){rr scan<amax>().a;}
  raw_type min(){rr scan<amin>().a;}
  vo fill(raw_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,raw_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 strs=V1<str>;uu gra=V2<edg>;uu cls=V1<cl>;uu tls=V1<tl>;

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 pot(T&a){au r=a.top();a.pop();rr r;}
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;}

struct io{io(){cin.tie(0)->sync_with_stdio(0);
  cout<<std::fixed<<std::setprecision(15);std::cerr<<nl;}}io;
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<<str(x<0,'-')<<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>&q){fe(q,e)o<<e<<sp;rr o;}
I(J T)os&O<<(os&o,qmax<T>q){wh(len(q))o<<pot(q)<<sp;rr o;}
I(J T)os&O<<(os&o,qmin<T>q){wh(len(q))o<<pot(q)<<sp;rr o;}
I(size_t n)os&O<<(os&o,cs bitset<n>&b){fo(i,n)o<<b[i];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 T,J U,J V)os&O<<(os&o,cs tr<T,U,V>&t){rr o<<t.a<<sp<<t.b<<sp<<t.c;}
I(J...A)os&O<<(os&o,cs tuple<A...>&t){apply([&](cs au&...a){ll i=0;(((o<<a<<str(++i!=sizeof...(a),sp))),...);},t);rr o;}
I(J V)os&O<<(os&o,cs std::vector<V>&v){fe(v,e)o<<e<<str(&e!=&rb(v),isv<V>?nl:sp);rr o;}
I(J...A)vo pp(cs A&...a){ll i=0;((cout<<a<<str(++i!=sizeof...(a),sp)),...);cout<<nl;}
I(J T,J U)is&O>>(is&i,cp<T,U>&c){rr i>>c.a>>c.b;}
I(J T,J U,J V)is&O>>(is&i,tr<T,U,V>&t){rr i>>t.a>>t.b>>t.c;}
I(J V)is&O>>(is&i,std::vector<V>&v){fe(v,e)i>>e;rr i;}
I(J...A)vo li(A&...a){(cin>>...>>a);}
I(J...A)vo vi(A&...a){fo(i,(len(a)&...))(cin>>...>>a[i]);}
u1 sien(cs str&b="a"){ST(s);u1 r;fe(s,e)r.eb(len(b)==1?e-b[0]:b.find_first_of(e));rr r;}
u2 sien(ll n,cs str&b="a"){u2 r;fo(n)r.eb(sien(b));rr r;}
I(J G)au ygi(G&g,ll m,bo f=1){ift<same<G,u2>,cls,tls>r(m);li(r);fe(r,e)ifc(same<G,u2>)g[e.a-=f].eb(e.b-=f);else g[e.a-=f].eb(e.b-=f,e.c);rr r;}
I(J G)au mgi(G&g,ll m,bo f=1){au r=ygi(g,m,f);fe(r,e)ifc(same<G,u2>)g[e.b].eb(e.a);else g[e.b].eb(e.a,e.c);rr r;}
I(J G)au ti(G&g,bo f=1){rr mgi(g,len(g)-1,f);}
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;}

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 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)dd bsd(F f,dd o,dd n){fo(l2(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;}
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 pw(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;}

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<<str(&e!=&rb(s),sp);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<<str(&e!=&rb(s),sp);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<<str(&e!=&rb(s),sp);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;}

auto flo_rng(ll n){
  V1<tuple<ll,ll,ll>>r;
  ll m=sqr(n),l=n/(m+1);
  fo(i,1,m+1)r.eb(n/i,i,i+1);
  of(i,1,l+1)r.eb(i,n/(i+1)+1,n/i+1);
  rr r;
}

int main(){ll T=1;fo(T)solve();}
vo solve(){
  LL(N);
  UL(N,a);

  map<ll,cls>g;
  fo(i,N){
    au t=flo_rng(a[i]);
    fe(t,a,b,c)if(b<=N*2)g[b].eb(i,a);
    if(a[i]+1<=N*2)g[a[i]+1].eb(i,0);
  }

  umap<ll>cnt;
  fo(i,N)cnt[a[i]]++;
  ll kind=len(cnt);
  u1 pre=a;

  ll ans=oo;
  ll mi=0;
  fe(g,x,v){
    fe(v,i,y){
      cnt[pre[i]]--;
      if(cnt[pre[i]]==0)cnt.erase(pre[i]);

      pre[i]=y;
      cnt[pre[i]]++;
    }
    if(amin(ans,(x+1)*len(cnt)))mi=x;
  }

  pp(mi);
  pp(ans);
}
0