結果

問題 No.2381 Gift Exchange Party
ユーザー cho435cho435
提出日時 2023-07-14 21:55:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 833 bytes
コンパイル時間 3,985 ms
コンパイル使用メモリ 261,716 KB
実行使用メモリ 7,612 KB
最終ジャッジ日時 2023-10-14 12:02:42
合計ジャッジ時間 6,477 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,968 KB
testcase_01 AC 6 ms
6,844 KB
testcase_02 AC 7 ms
6,848 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 7 ms
7,016 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 7 ms
6,940 KB
testcase_12 AC 6 ms
6,828 KB
testcase_13 AC 6 ms
6,776 KB
testcase_14 AC 6 ms
6,844 KB
testcase_15 AC 6 ms
7,036 KB
testcase_16 AC 6 ms
6,844 KB
testcase_17 AC 6 ms
6,828 KB
testcase_18 AC 6 ms
6,820 KB
testcase_19 AC 6 ms
7,024 KB
testcase_20 AC 51 ms
6,832 KB
testcase_21 RE -
testcase_22 AC 52 ms
6,928 KB
testcase_23 AC 52 ms
6,844 KB
testcase_24 AC 7 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

// combination MOD
const int MOD=998244353;
const int MAX_N=2e5;
vector<mint> fac(MAX_N+1,1);
vector<ll> finv(MAX_N+1,1);
vector<ll> inv(MAX_N+1,1);
void comb_setup(){
	for(int i=2;i<=MAX_N;i++){
		fac.at(i)=(fac.at(i-1)*i);
		inv.at(i)=MOD-(inv.at(MOD%i)*(MOD/i))%MOD;
		finv.at(i)=(finv.at(i-1)*inv.at(i))%MOD;
	}
}
mint comb(int n,int k){
	if(n<k) return 0;
	return fac.at(n)*finv.at(n-k)*finv.at(k);
}

int main(){
	comb_setup();
	int n,p;
	cin>>n>>p;
	mint ans=fac.at(n);
	for(ll i=0;i*p<=n;i++){
		mint tmp=comb(n,i*p);
		tmp*=fac.at(i*p);
		tmp/=fac.at(p).pow(i);
		tmp/=fac.at(i);
		tmp*=fac.at(p-1).pow(i);
		ans-=tmp;
	}
	cout<<ans.val()<<endl;
}
0