結果

問題 No.2243 Coaching Schedule
ユーザー lgswdnlgswdn
提出日時 2023-05-11 09:51:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,565 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 202,728 KB
実行使用メモリ 18,820 KB
最終ジャッジ日時 2023-08-18 06:29:38
合計ジャッジ時間 16,266 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
17,804 KB
testcase_01 AC 4 ms
17,888 KB
testcase_02 AC 4 ms
17,820 KB
testcase_03 AC 4 ms
17,820 KB
testcase_04 AC 6 ms
17,832 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 28 ms
18,488 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 86 ms
18,816 KB
testcase_21 AC 45 ms
18,660 KB
testcase_22 AC 43 ms
18,656 KB
testcase_23 AC 10 ms
17,996 KB
testcase_24 AC 56 ms
18,820 KB
testcase_25 AC 12 ms
18,108 KB
testcase_26 AC 23 ms
18,360 KB
testcase_27 AC 60 ms
18,664 KB
testcase_28 AC 12 ms
18,160 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 42 ms
18,700 KB
testcase_33 AC 24 ms
18,348 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define popc __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef long double ld;

int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=2e5+9,mod=998244353;

int m,n,a[N],f[N],fac[N],ifac[N],inv[N],ans,b[N],g[N],x[N],y[N];
vi p;

int ksm(int x,int y,int res=1) {
    for(;y;y>>=1,x=x*x%mod) if(y%2==1) res=res*x%mod;
    return res;
}
void pre(int n) {
    inv[0]=inv[1]=fac[0]=ifac[0]=1;
    rep(i,1,n) fac[i]=fac[i-1]*i%mod;
    ifac[n]=ksm(fac[n],mod-2);
    per(i,n-1,1) ifac[i]=ifac[i+1]*(i+1)%mod;
    rep(i,2,n) inv[i]=ifac[i]*fac[i-1]%mod;
}
int C(int x,int y) {
    if(x<0||y<0||x<y) return 0;
    else return fac[x]*ifac[y]%mod*ifac[x-y]%mod;
}

namespace Poly {
  const int mod=998244353,gg=3,ig=332748118;
  int lim,r[N],a[N],b[N],c[N],d[N],e[N],h[N];
  void init(int n) {
    int l=0;
    for(lim=1;lim<=n;lim<<=1,l++);
    rep(i,0,lim) r[i]=(r[i>>1]>>1)|((i&1)<<l-1);
  }
  int pls(int x,int y) {return x+=y,x>=mod?x-mod:x;}
  int mns(int x,int y) {return x-=y,x<0?x+=mod:x;}
  void ntt(int *f,int lim,int t) {
    rep(i,0,lim-1) if(i<r[i]) swap(f[i],f[r[i]]);
    for(int len=1;len<lim;len<<=1) {
      int dw=ksm(t>0?gg:ig,(mod-1)/(len*2));
      for(int i=0;i<lim;i+=len*2) {
        int w=1;
        for(int j=0;j<len;j++,w=w*dw%mod) {
          int x=f[i+j], y=w*f[i+j+len]%mod;
          f[i+j]=pls(x,y), f[i+j+len]=mns(x,y);
        }
      }
    }
    if(t==-1) {
      int iv=ksm(lim,mod-2);
      rep(i,0,lim) f[i]=f[i]*iv%mod;
    }
  }
  void _mul(int *f,int *g,int len) {
    init(len);
    ntt(f,lim,1), ntt(g,lim,1);
    rep(i,0,lim-1) f[i]=f[i]*g[i]%mod;
    ntt(f,lim,-1);
  }
}

signed main() {
  m=read(), n=read(); pre(2*n);
  rep(i,1,n) a[read()]++;
  rep(i,1,m) b[a[i]]++;
  rep(i,1,n) if(b[i]) p.eb(i);
  rep(i,1,n) {
    f[i]=1;
    for(int k:p) f[i]=(f[i]*ksm(C(i,k),b[k]))%mod;
  }
  rep(i,1,n) if(i&1) x[i]=mod-fac[i]; else x[i]=fac[i];
  rep(i,0,n) y[i]=ifac[n-i]%mod;
  Poly::_mul(x,y,2*n);
  rep(i,1,n) g[i]=x[i+n]*ifac[i]%mod;
  rep(i,1,n) if(i&1) g[i]=mod-g[i];
  rep(i,1,n) ans=(ans+f[i]*g[i])%mod;
  rep(i,1,m) ans=ans*fac[a[i]]%mod;
  printf("%lld\n",ans);
  return 0;
}
0