結果
| 問題 | 
                            No.1856 Mex Sum 2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             蜜蜂
                         | 
                    
| 提出日時 | 2021-04-15 08:04:31 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                            (最新)
                                AC
                                 
                             
                            (最初)
                            
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 3,008 bytes | 
| コンパイル時間 | 4,329 ms | 
| コンパイル使用メモリ | 239,824 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-04 04:41:09 | 
| 合計ジャッジ時間 | 24,107 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 2 | 
| other | AC * 8 WA * 56 | 
ソースコード
//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";
}
            
            
            
        
            
蜜蜂