結果

問題 No.1062 素敵なスコア
ユーザー tko919tko919
提出日時 2020-05-22 23:35:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 3,992 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 175,008 KB
実行使用メモリ 24,320 KB
最終ジャッジ日時 2024-04-15 19:08:13
合計ジャッジ時間 4,132 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
22,016 KB
testcase_01 AC 26 ms
22,144 KB
testcase_02 AC 26 ms
22,100 KB
testcase_03 AC 26 ms
22,072 KB
testcase_04 AC 27 ms
22,160 KB
testcase_05 AC 27 ms
22,236 KB
testcase_06 AC 27 ms
21,956 KB
testcase_07 AC 29 ms
22,016 KB
testcase_08 AC 26 ms
22,096 KB
testcase_09 AC 26 ms
22,144 KB
testcase_10 AC 26 ms
21,964 KB
testcase_11 AC 28 ms
21,952 KB
testcase_12 AC 26 ms
22,140 KB
testcase_13 AC 26 ms
21,940 KB
testcase_14 AC 26 ms
22,016 KB
testcase_15 AC 25 ms
22,144 KB
testcase_16 AC 27 ms
22,144 KB
testcase_17 AC 26 ms
22,240 KB
testcase_18 AC 34 ms
23,072 KB
testcase_19 AC 38 ms
23,680 KB
testcase_20 AC 32 ms
23,040 KB
testcase_21 AC 31 ms
23,196 KB
testcase_22 AC 38 ms
23,736 KB
testcase_23 AC 31 ms
23,040 KB
testcase_24 AC 28 ms
22,668 KB
testcase_25 AC 31 ms
23,040 KB
testcase_26 AC 32 ms
23,168 KB
testcase_27 AC 28 ms
22,400 KB
testcase_28 AC 38 ms
23,648 KB
testcase_29 AC 29 ms
22,600 KB
testcase_30 AC 38 ms
23,872 KB
testcase_31 AC 38 ms
24,320 KB
testcase_32 AC 25 ms
22,232 KB
testcase_33 AC 38 ms
24,136 KB
testcase_34 AC 37 ms
24,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<unsigned mod=998244353>struct fp {
   unsigned v;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=v,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0){x+=mod;} return x;
   }
   fp():v(0){}
   fp(ll x):v(x>=0?x%mod:mod+(x%mod)){}
   fp operator-()const{return fp(-v);}
   fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;}
   fp& operator+=(const fp& x){if((v+=x.v)>=mod)v-=mod; return *this;}
   fp& operator-=(const fp& x){if((v+=mod-x.v)>=mod)v-=mod; return *this;}
   fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;}
   fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;}
   fp operator+(const fp& x)const{return fp(*this)+=x;}
   fp operator-(const fp& x)const{return fp(*this)-=x;}
   fp operator*(const fp& x)const{return fp(*this)*=x;}
   fp operator/(const fp& x)const{return fp(*this)/=x;}
   bool operator==(const fp& x)const{return v==x.v;}
   bool operator!=(const fp& x)const{return v!=x.v;}
}; using Fp=fp<>;
template<typename T>struct factorial {
   vector<T> Fact,Finv,Inv;
   factorial(int maxx){
      Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx);
      Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1;
      rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv();
      for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];}
   }
   T fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   T inv(int n){return Inv[n];}
   T nPr(int n,int r){if(n<0||n<r||r<0)return Fp(0);else return Fact[n]*Finv[n-r];}
   T nCr(int n,int r){if(n<0||n<r||r<0)return Fp(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

template<typename T,unsigned p>struct NTT{
   vector<T> rt,irt;
   NTT(int lg=21){
      const unsigned m=T(-1).v; T prt=p;
      rt.resize(1<<lg,1); irt.resize(1<<lg,1);
      for(int w=0;w<lg;w++){
         int mask=1<<w; T g=prt.pow(m>>w),ig=g.inv();
         for(int i=0;i<mask-1;i++){
            rt[mask+i+1]=g*rt[mask+i];
            irt[mask+i+1]=ig*irt[mask+i];
         }
      }
   }
   void ntt(vector<T>& f,bool inv=0){
      int n=f.size();
      if(inv){
         for(int i=1;i<n;i<<=1)for(int j=0;j<n;j+=i*2)for(int k=0;k<i;k++){
            f[i+j+k]*=irt[i*2+k]; T tmp=f[j+k]-f[i+j+k];
            f[j+k]+=f[i+j+k]; f[i+j+k]=tmp;
         } T mul=T(n).inv(); rep(i,0,n)f[i]*=mul;
      }else{
         for(int i=n>>1;i;i>>=1)for(int j=0;j<n;j+=i*2)for(int k=0;k<i;k++){
            T tmp=f[j+k]-f[i+j+k]; f[j+k]+=f[i+j+k]; f[i+j+k]=tmp*rt[i*2+k];
         }
      }
   }
   vector<T> conv(vector<T> a,vector<T> b,bool same){
      if(a.empty() and b.empty())return vector<T>();
      int n=a.size()+b.size()-1,m=1; while(m<n)m<<=1;
      a.resize(m); ntt(a);
      if(same)rep(i,0,m)a[i]*=a[i];
      else{b.resize(m); ntt(b); rep(i,0,m)a[i]*=b[i];}
      ntt(a,1); a.resize(n); return a;
   }
};
NTT<Fp,3> ntt; inline vector<Fp> multiply(vector<Fp> a,vector<Fp> b,bool same=0){return ntt.conv(a,b,same);};

factorial<Fp> fact(201010);

int main(){
   int n,x,y; cin>>n>>x>>y;
   if(x>y)swap(x,y);
   int a=x,b=y-x,c=n-y;
   vector<Fp> f(a),g(c);
   rep(i,0,a){
      f[i]=fact.fact(i,1)*fact.fact(a-i-1,1);
   }
   rep(i,0,c){
      g[i]=fact.fact(i,1)*fact.fact(c-i-1,1);
   }
   f=multiply(f,g); Fp res;
   rep(i,0,a+c-1){
      res+=f[i]*fact.fact(i)*fact.fact(n-i-2);
   }
   res*=fact.fact(a)*fact.fact(c)*2;
   res+=(Fp(1LL*a*a)+Fp(1LL*b*b)+Fp(1LL*c*c))*fact.fact(n-1);
   cout<<res.v<<endl;
   return 0;
}
0