結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー twooimp2twooimp2
提出日時 2024-02-24 19:03:46
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 6,654 ms
コンパイル使用メモリ 299,172 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-29 10:13:18
合計ジャッジ時間 7,151 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;

void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

ll modpow(ll a,ll n,ll mod){
  ll res=1;
  while(n>0){
    if(n&1){
      res=res*a%mod;
    }
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a,ll m){
	ll b=m,u=1,v=0;
	while(b){
		ll t=a/b;
		a-=t*b;
		swap(a,b);
		u-=t*v;
		swap(u,v);
	}
	u%=m;
	if(u<0) u+=m;
	return u;
}

int main(){
  IO();
  ll n;
  cin>>n;
  ll m;
  cin>>m;
  if(n<m){
    cout<<0<<endl;
    exit(0);
  }
  ll mod=998244353;
  ll ans=modpow(2,n,mod);
  ll num=1;
  for(ll i=0;i<m;i++){
    ans-=num; ans+=mod; ans%=mod;
    num*=n-i; num%=mod;
    num*=modinv(i+1,mod); num%=mod;
  }
  cout<<ans<<endl;
}
0