結果

問題 No.1856 Mex Sum 2
ユーザー 蜜蜂蜜蜂
提出日時 2021-04-15 08:04:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,008 bytes
コンパイル時間 4,087 ms
コンパイル使用メモリ 236,660 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-17 07:51:20
合計ジャッジ時間 25,466 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,380 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 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 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 1 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 4 ms
4,376 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;
  }

  //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]*pow_mod(m-i,n-j,mod))%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]*pow_mod(m-i,n-j,mod))%mod*invfac[n-j];
      count[i]%=mod;
    }

    

    //cout<<endl;
  }

  ll ans=0,p=(pow2*fac[n])%mod;

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

    count[i]*=p;
    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