結果

問題 No.2033 Chromatic Duel
ユーザー ShirotsumeShirotsume
提出日時 2022-07-03 01:32:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,939 bytes
コンパイル時間 3,515 ms
コンパイル使用メモリ 227,836 KB
実行使用メモリ 15,812 KB
最終ジャッジ日時 2023-09-15 14:18:11
合計ジャッジ時間 6,025 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
15,524 KB
testcase_01 AC 15 ms
15,808 KB
testcase_02 AC 13 ms
15,776 KB
testcase_03 AC 13 ms
15,504 KB
testcase_04 AC 13 ms
15,640 KB
testcase_05 AC 14 ms
15,576 KB
testcase_06 AC 14 ms
15,692 KB
testcase_07 AC 13 ms
15,572 KB
testcase_08 AC 13 ms
15,572 KB
testcase_09 AC 13 ms
15,812 KB
testcase_10 AC 13 ms
15,708 KB
testcase_11 AC 13 ms
15,520 KB
testcase_12 AC 13 ms
15,584 KB
testcase_13 AC 14 ms
15,576 KB
testcase_14 AC 14 ms
15,696 KB
testcase_15 AC 14 ms
15,568 KB
testcase_16 AC 12 ms
15,520 KB
testcase_17 AC 13 ms
15,572 KB
testcase_18 AC 12 ms
15,576 KB
testcase_19 AC 13 ms
15,520 KB
testcase_20 AC 12 ms
15,692 KB
testcase_21 AC 13 ms
15,576 KB
testcase_22 AC 14 ms
15,588 KB
testcase_23 AC 12 ms
15,692 KB
testcase_24 AC 12 ms
15,524 KB
testcase_25 AC 13 ms
15,584 KB
testcase_26 AC 12 ms
15,516 KB
testcase_27 AC 11 ms
15,576 KB
testcase_28 AC 12 ms
15,504 KB
testcase_29 AC 12 ms
15,628 KB
testcase_30 AC 12 ms
15,812 KB
testcase_31 AC 12 ms
15,576 KB
testcase_32 AC 12 ms
15,572 KB
testcase_33 AC 14 ms
15,692 KB
testcase_34 AC 13 ms
15,628 KB
testcase_35 AC 12 ms
15,624 KB
testcase_36 AC 15 ms
15,524 KB
testcase_37 AC 14 ms
15,524 KB
testcase_38 AC 12 ms
15,772 KB
testcase_39 AC 15 ms
15,584 KB
testcase_40 AC 14 ms
15,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAX = 520000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll homop(int n, int k){
    if (n == k && k == 0) return 1;
    return COM(n + k - 1, k);
}
int main(void)
{
    COMinit();
    int n, b, w;
    cin >> n >> b >> w;
    int y = n - b - w;
    int z = n - b;
    mint ans = 0;
    rep(one, b + 2){
        if((y - one) % 2 == 0){
            int two = (y - one) / 2;
            int zero = b + 1 - one - two;
            int summ = z - one - 2 * two;
            mint pat = COM(b - 1, two) * COM(zero + one, zero);
            ans += pat * homop(two, summ);
        }
        y++;
        if((y - one) % 2 == 0){
            int two = (y - one) / 2;
            int zero = b + 1 - one - two;
            int summ = z - one - 2 * two;
            two--;
            mint pat = COM(b - 1, two) * COM(zero + one, zero);
            ans += 2 * pat * homop(two + 1, summ);
        }
        y++;
        if((y - one) % 2 == 0){
            int two = (y - one) / 2;
            int zero = b + 1 - one - two;
            int summ = z - one - 2 * two;
            two-=2;
            mint pat = COM(b - 1, two) * COM(zero + one, zero);
            ans += pat * homop(two + 2, summ);
        }
        y -= 2;

    }
    cout << ans.val() << endl;
    return 0;

}
0