結果

問題 No.2381 Gift Exchange Party
ユーザー 👑 獅子座じゃない人獅子座じゃない人
提出日時 2023-07-14 22:41:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 3,808 ms
コンパイル使用メモリ 228,080 KB
実行使用メモリ 5,460 KB
最終ジャッジ日時 2023-10-14 12:57:38
合計ジャッジ時間 5,487 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 12 ms
4,348 KB
testcase_03 AC 7 ms
4,352 KB
testcase_04 AC 16 ms
4,352 KB
testcase_05 AC 30 ms
5,148 KB
testcase_06 AC 14 ms
4,352 KB
testcase_07 AC 14 ms
4,348 KB
testcase_08 AC 25 ms
4,892 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 11 ms
4,352 KB
testcase_11 AC 18 ms
4,640 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 12 ms
4,352 KB
testcase_14 AC 21 ms
4,628 KB
testcase_15 AC 10 ms
4,352 KB
testcase_16 AC 11 ms
4,348 KB
testcase_17 AC 26 ms
5,144 KB
testcase_18 AC 15 ms
4,348 KB
testcase_19 AC 16 ms
4,356 KB
testcase_20 AC 45 ms
5,460 KB
testcase_21 AC 31 ms
5,364 KB
testcase_22 AC 45 ms
5,420 KB
testcase_23 AC 45 ms
5,416 KB
testcase_24 AC 14 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353;

int main(void) {
    int n,p;
    cin >> n >> p;
    vector<mint> inv(n+1,1);
    vector<mint> fact(n+1,1);
    vector<mint> finv(n+1,1);
    for(int i=2;i<=n;++i){
        inv[i]=mint(i).inv();
        fact[i]=fact[i-1]*i;
        finv[i]=finv[i-1]*inv[i];
    }
    mint ans=fact[n];
    mint invpow=1;
    for(int i=0;i*p<=n;++i){
        ans-=fact[n]*invpow*finv[n-i*p]*finv[i];
        invpow/=p;
    }
    cout << ans.val() << endl;
    return 0;
}
0