結果
| 問題 |
No.1856 Mex Sum 2
|
| コンテスト | |
| ユーザー |
蜜蜂
|
| 提出日時 | 2021-04-17 22:40:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 501 ms / 3,000 ms |
| コード長 | 2,842 bytes |
| コンパイル時間 | 4,403 ms |
| コンパイル使用メモリ | 241,176 KB |
| 実行使用メモリ | 83,712 KB |
| 最終ジャッジ日時 | 2024-06-28 13:18:58 |
| 合計ジャッジ時間 | 20,386 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 64 |
ソースコード
//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;
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";
}
蜜蜂