結果

問題 No.1856 Mex Sum 2
ユーザー 蜜蜂蜜蜂
提出日時 2021-04-15 22:59:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,182 bytes
コンパイル時間 4,177 ms
コンパイル使用メモリ 239,832 KB
実行使用メモリ 83,788 KB
最終ジャッジ日時 2023-09-17 07:52:10
合計ジャッジ時間 21,089 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 5 ms
5,932 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 117 ms
83,512 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 1.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)

constexpr ll mod = 998244353;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);


  clock_t start = clock(); 

  ll n,m;
  cin>>n>>m;

  ll pow2=1,factional=1;

  //fac[i] := i! (i=0のときfac[i]=1)
  vll fac(n+100);
  vll invfac(n+100);
  rep(i,0,n+50){
    fac[i]=factional;
    invfac[i]=inv_mod(fac[i],mod);
    factional*=(i+1);
    factional%=mod;
  }

  //powmod[i][j] := (m-i)^(n-j)
  vvll powmod(5100,vll(n+1));
  rep(i,0,5100){
    powmod[i][n]=1;
    per(j,n-1,0){
      powmod[i][j]=powmod[i][j+1]*(m-i);
      powmod[i][j]%=mod;
    }
  }

  //mul := FFTするときにかけるやつ 0 + (2^1 - 1)/(2^1 * 1!) x + (2^2 - 1)/(2^2 * 2!) x^2 + ... といった具合
  vll mul(n+1,0);
  rep(i,1,n+1){
    pow2*=2;
    pow2%=mod;
    mul[i]=pow2-1;
    mul[i]*=inv_mod(pow2*fac[i],mod);
    mul[i]%=mod;
    //cout<<mul[i]<<" ";
  }
  //cout<<endl;

  //now := 今のdp配列を多項式にして保存
  //count[i] := mex>=iとなるようなA'の数(を全通りの数列に対して足し合わせた合計)
  vll now(1,1);
  vll count(n+1,0);
  rep(i,0,min(n,m+1)){

    /*

    now=move(convolution(now,mul));
    while(now.size()>n+10){
      now.pop_back();
    }
    rep(j,0,n+1){
      //cout<<get[j]<<" ";
      now.pb(now[j]);

      //pow_modのところは残りを埋める方法を反映
      //inv_modのところは二項係数の整理 100C2 * 98C4 = 100!/(2! * 98!) * 98!/(4! * 94!) = 100!(2! * 4! * 94!) の94!のところ

      count[i]+=(now[j]*powmod[i][j])%mod*invfac[n-j];
      count[i]%=mod;
    }

    */


    

    vll get=convolution(now,mul);
    now.clear();
    rep(j,0,n+1){
      //cout<<get[j]<<" ";
      now.pb(get[j]);

      //pow_modのところは残りを埋める方法を反映
      //inv_modのところは二項係数の整理 100C2 * 98C4 = 100!/(2! * 98!) * 98!/(4! * 94!) = 100!(2! * 4! * 94!) の94!のところ

      count[i]+=(get[j]*powmod[i][j])%mod*invfac[n-j];
      count[i]%=mod;
    }

    

    //cout<<endl;
  }

  ll ans=0;

  rep(i,0,n+1){
    //一括して2^N * N! をかける

    count[i]*=(pow2*fac[n])%mod;
    count[i]%=mod;

    //cout<<count[i]<<" ";
  }

  per(i,n,0){
    //count[i]の差分を取ることで各mexごとに値が求まる

    ans+=count[i]*(i+1);
    ans%=mod;
    ans+=mod;
    if(i>0){
      count[i-1]-=count[i];
      count[i-1]%=mod;
    }
  }

  cout<<(ans%mod+mod)%mod<<endl;



  clock_t end = clock();     // 終了時間
  //cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
}
0