結果
問題 | No.2381 Gift Exchange Party |
ユーザー | butsurizuki |
提出日時 | 2023-07-14 21:35:19 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 1,215 bytes |
コンパイル時間 | 5,627 ms |
コンパイル使用メモリ | 243,572 KB |
実行使用メモリ | 19,856 KB |
最終ジャッジ日時 | 2023-10-14 11:37:18 |
合計ジャッジ時間 | 4,761 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
19,856 KB |
testcase_01 | AC | 16 ms
19,636 KB |
testcase_02 | AC | 16 ms
19,816 KB |
testcase_03 | AC | 16 ms
19,720 KB |
testcase_04 | AC | 16 ms
19,820 KB |
testcase_05 | AC | 16 ms
19,720 KB |
testcase_06 | AC | 16 ms
19,636 KB |
testcase_07 | AC | 16 ms
19,772 KB |
testcase_08 | AC | 16 ms
19,740 KB |
testcase_09 | AC | 16 ms
19,716 KB |
testcase_10 | AC | 16 ms
19,636 KB |
testcase_11 | AC | 16 ms
19,720 KB |
testcase_12 | AC | 16 ms
19,712 KB |
testcase_13 | AC | 16 ms
19,812 KB |
testcase_14 | AC | 16 ms
19,704 KB |
testcase_15 | AC | 16 ms
19,776 KB |
testcase_16 | AC | 17 ms
19,648 KB |
testcase_17 | AC | 16 ms
19,848 KB |
testcase_18 | AC | 16 ms
19,636 KB |
testcase_19 | AC | 17 ms
19,652 KB |
testcase_20 | AC | 18 ms
19,648 KB |
testcase_21 | AC | 16 ms
19,744 KB |
testcase_22 | AC | 17 ms
19,740 KB |
testcase_23 | AC | 17 ms
19,716 KB |
testcase_24 | AC | 17 ms
19,812 KB |
ソースコード
// Counting Template #include<bits/stdc++.h> using namespace std; #define mod 998244353 #define FACSIZE 1048576 long long power(long long a,long long b){ long long x=1,y=a; while(b>0){ if(b&1ll){ x=(x*y)%mod; } y=(y*y)%mod; b>>=1; } return x%mod; } long long modular_inverse(long long n){ return power(n,mod-2); } long long factorial[FACSIZE]; long long invfact[FACSIZE]; void cfact(){ long long i; factorial[0]=1; factorial[1]=1; for(i=2;i<FACSIZE;i++){ factorial[i]=factorial[i-1]*i; factorial[i]%=mod; } invfact[FACSIZE-1]=modular_inverse(factorial[FACSIZE-1]); for(i=FACSIZE-2;i>=0;i--){ invfact[i]=invfact[i+1]*(i+1); invfact[i]%=mod; } } long long calcnCr(long long n,long long k){ if(k<0 || n<k){return 0;} return (factorial[n]*((invfact[k]*invfact[n-k])%mod))%mod; } int main(){ cfact(); ios::sync_with_stdio(false); cin.tie(nullptr); long long n,p; cin >> n >> p; long long res=1; long long del=1; for(long long i=1;i*p<=n;i++){ del*=calcnCr(n-(i-1)*p,p);del%=mod; del*=factorial[p-1];del%=mod; res+=(del*invfact[i]);res%=mod; } res=(mod+factorial[n]-res)%mod; cout << res << "\n"; return 0; }