結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー FplusFplusF
提出日時 2022-11-25 21:23:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,311 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 206,044 KB
最終ジャッジ日時 2025-02-08 23:42:14
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 10 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i=0;i<(long long)(n);i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
ll modpow(ll a,ll b,ll mod){
    if(b==0) return 1;
    ll p=a,ret=1;
    for(ll i=0;i<=62;i++){
        if(b&(1ll<<i)){
            ret*=p;
            ret%=mod;
        }
        p=(p%mod)*(p%mod);
        p%=mod;
    }
    return ret;
}
ll division(ll a,ll b,ll mod){
    return (a*modpow(b,mod-2,mod))%mod;
}
map<ll,map<ll,ll>> factorial;
ll nCr(ll n,ll r,ll mod){
    if(n<0||r<0) return 0;
    if(n<r) return 0;
    if(factorial[mod][n]==0){
        ll x=1;
        factorial[mod][0]=1;
        for(ll i=1;i<=1000010;i++){    //iの上限は適宜変更
            x*=i;
            x%=mod;
            factorial[mod][i]=x;
        }
    }
    return division(factorial[mod][n],factorial[mod][r]*factorial[mod][n-r],mod);
}
int main(){
    const ll mod=998244353;
    ll n,m;
    cin >> n >> m;
    ll sum=0;
    rep(i,m){
        sum+=nCr(n,i,mod);
        sum%=mod;
    }
    cout << (modpow(2,n,mod)-sum+mod)%mod << endl;
}
0