結果

問題 No.2084 Mex Subset For All Sequences
ユーザー 蜜蜂蜜蜂
提出日時 2022-09-25 22:01:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,889 bytes
コンパイル時間 4,297 ms
コンパイル使用メモリ 238,388 KB
実行使用メモリ 814,720 KB
最終ジャッジ日時 2023-08-24 02:13:17
合計ジャッジ時間 7,077 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 8 ms
7,276 KB
testcase_03 AC 6 ms
6,316 KB
testcase_04 AC 6 ms
6,536 KB
testcase_05 AC 4 ms
5,220 KB
testcase_06 AC 5 ms
5,972 KB
testcase_07 AC 7 ms
7,404 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//https://yukicoder.me/problems/no/1856
//g++ kyouyuu1.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;
  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);
  ll ans=0;
  vll get;
  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;
    }

    */


    

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

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

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


    //cout<<endl;
  }

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

  cout<<ans%mod<<endl;

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