結果

問題 No.1960 Guruguru Permutation
ユーザー trineutrontrineutron
提出日時 2022-05-27 22:20:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 207,080 KB
実行使用メモリ 5,008 KB
最終ジャッジ日時 2023-10-20 20:26:03
合計ジャッジ時間 3,452 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 20 ms
4,348 KB
testcase_05 AC 9 ms
4,348 KB
testcase_06 AC 12 ms
4,348 KB
testcase_07 AC 33 ms
4,760 KB
testcase_08 AC 23 ms
4,348 KB
testcase_09 AC 32 ms
4,760 KB
testcase_10 AC 20 ms
4,348 KB
testcase_11 AC 17 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 28 ms
4,760 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 13 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 33 ms
5,008 KB
testcase_19 AC 36 ms
5,008 KB
testcase_20 AC 34 ms
5,008 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 35 ms
5,008 KB
testcase_23 AC 35 ms
5,008 KB
testcase_24 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

vector<mint> fact, inv;

void init(int n) {
    fact.push_back(1);
    inv.push_back(1);
    for (int i = 0; i < n; i++) {
        fact.push_back(fact.at(i) * (i + 1));
        inv.push_back(fact.at(i + 1).inv());
    }
}

mint ncr(int n, int r) {
    if (r < 0 or n < r) {
        return 0;
    }
    return fact.at(n) * inv.at(r) * inv.at(n - r);
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    if (m + k > n) {
        int d = m + k - n;
        n -= d;
        m -= d;
        k -= d;
    }
    init(n);
    mint ans = 0;
    for (int i = 0; i <= n; i++) {
        ans += ncr(m, i) * ncr(k, i) * fact.at(i);
    }
    ans *= fact.at(n) * inv.at(m + k);
    cout << ans.val() << endl;
    return 0;
}
0