結果
問題 | No.2381 Gift Exchange Party |
ユーザー | Today03 |
提出日時 | 2023-07-14 22:44:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 951 bytes |
コンパイル時間 | 2,116 ms |
コンパイル使用メモリ | 205,072 KB |
実行使用メモリ | 4,868 KB |
最終ジャッジ日時 | 2023-10-14 13:01:16 |
合計ジャッジ時間 | 3,465 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,372 KB |
testcase_01 | AC | 1 ms
4,368 KB |
testcase_02 | AC | 11 ms
4,368 KB |
testcase_03 | AC | 7 ms
4,368 KB |
testcase_04 | AC | 16 ms
4,368 KB |
testcase_05 | AC | 28 ms
4,676 KB |
testcase_06 | AC | 14 ms
4,372 KB |
testcase_07 | AC | 14 ms
4,368 KB |
testcase_08 | AC | 24 ms
4,372 KB |
testcase_09 | AC | 2 ms
4,372 KB |
testcase_10 | AC | 10 ms
4,372 KB |
testcase_11 | AC | 17 ms
4,368 KB |
testcase_12 | AC | 4 ms
4,368 KB |
testcase_13 | AC | 11 ms
4,372 KB |
testcase_14 | AC | 20 ms
4,372 KB |
testcase_15 | AC | 10 ms
4,372 KB |
testcase_16 | AC | 10 ms
4,368 KB |
testcase_17 | AC | 24 ms
4,476 KB |
testcase_18 | AC | 15 ms
4,368 KB |
testcase_19 | AC | 15 ms
4,372 KB |
testcase_20 | AC | 51 ms
4,680 KB |
testcase_21 | AC | 29 ms
4,636 KB |
testcase_22 | AC | 52 ms
4,848 KB |
testcase_23 | AC | 52 ms
4,868 KB |
testcase_24 | AC | 13 ms
4,368 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> using mint=atcoder::modint998244353; template <typename mint> struct combination { vector<mint> fact,factinv; combination(int n) { fact.resize(n+1); factinv.resize(n+1); fact[0]=1; for (int i=1;i<=n;i++) { fact[i]=fact[i-1]*i; } for (int i=0;i<=n;i++) { factinv[i]=fact[i].inv(); } } mint nCr(long long n,long long r) { if (n<0||r<0||n-r<0) { return 0; } return fact[n]*factinv[r]*factinv[n-r]; } mint nPr(long long n,long long r) { if (n<0||r<0||n-r<0) { return 0; } return fact[n]*factinv[n-r]; } }; int main() { int n; long long p; cin>>n>>p; combination<mint> C(n); mint ans=C.fact[n]-1; mint pre=1,tmp=1; for (int i=1;p*i<=n;i++) { pre*=C.nCr(n-p*(i-1),p); tmp*=i; mint fact=(C.fact[p-1]).pow(i); ans-=pre*fact/tmp; } cout<<ans.val()<<endl; }