結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー twooimp2twooimp2
提出日時 2024-02-24 19:07:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 7,061 ms
コンパイル使用メモリ 301,768 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-24 19:07:29
合計ジャッジ時間 7,302 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 4 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 4 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 29 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 25 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 1 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 1 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

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;
using lll=__int128;

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);
  }
  lll mod=998244353;
  lll ans=modpow(2,n,mod);
  lll num=1;
  for(lll i=0;i<m;i++){
    ans-=num; while(ans<0){ans+=mod;} ans%=mod;
    num*=(lll)(n)-i; num%=mod;
    num*=modinv(i+1,mod); num%=mod;
  }
  string s;
  while(ans){
    ll r=ans%10;;
    ans/=10;
    s+=r+'0';
  }
  reverse(s.begin(),s.end());
  if(s.size()){
    cout<<s<<endl;
  }else{
    cout<<0<<endl;
  }
}
0