結果

問題 No.2033 Chromatic Duel
ユーザー JashinchanJashinchan
提出日時 2022-08-24 11:24:50
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,373 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 32,896 KB
実行使用メモリ 12,840 KB
最終ジャッジ日時 2024-04-20 02:13:45
合計ジャッジ時間 1,928 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
12,728 KB
testcase_01 WA -
testcase_02 AC 9 ms
12,756 KB
testcase_03 WA -
testcase_04 AC 10 ms
12,728 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 12 ms
12,824 KB
testcase_10 WA -
testcase_11 AC 11 ms
12,724 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 10 ms
12,828 KB
testcase_20 AC 10 ms
12,784 KB
testcase_21 AC 14 ms
12,772 KB
testcase_22 AC 14 ms
12,724 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 13 ms
12,792 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 10 ms
12,720 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 9 ms
12,768 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 18 ms
12,748 KB
testcase_37 AC 17 ms
12,724 KB
testcase_38 AC 10 ms
12,824 KB
testcase_39 AC 18 ms
12,800 KB
testcase_40 AC 17 ms
12,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const long long mod = 998244353LL;
long long fact_table[700000];
long long invfact_table[700000];
long long pow_mod(long long a, long long k, long long m)
{
    long long ret = 1LL;
    while (k > 0)
    {
        if (k & 1)
            ret = (long long)((__int128_t)ret * a % m);
        a = (long long)((__int128_t)a * a % m);
        k >>= 1;
    }
    return ret;
}
void init_table(void)
{
    fact_table[0] = 1;
    for (int i = 1; i < 700000; ++i)
        fact_table[i] = fact_table[i - 1] * i % mod;
    invfact_table[699999] = pow_mod(fact_table[699999], mod - 2, mod);
    for (int i = 699998; i >= 0; --i)
        invfact_table[i] = invfact_table[i + 1] * (i + 1) % mod;
}
long long nCr_mod(long long n, long long r, long long m)
{
    if (r == 0)
        return 1;
    if (n < 0 || r < 0)
        return 0;
    if (n < r)
        return 0;
    return fact_table[n] * invfact_table[r] % m * invfact_table[n - r] % m;
}
long long nHr_mod(long long n, long long r, long long m)
{
    if (n == 0 || r == 0)
        return 1;
    return nCr_mod(n + r - 1, r, mod);
}

int main(void)
{
    init_table();

    long long n, b, w;
    scanf("%lld %lld %lld", &n, &b, &w);
    long long k = n - b - w;
    long long s = n - b;
    long long ans = 0LL;
    for (int i = 0; i <= b + 1; ++i)
    {
        if (!((k - i) & 1))
        {
            long long t = (k - i) / 2;
            long long x = b + 1 - i - t;
            long long y = s - i - 2 * t;
            long long z = nCr_mod(b - 1, t, mod) * nCr_mod(x + i, x, mod) % mod;
            ans = (ans + z * nHr_mod(t, y, mod)) % mod;
        }
        k++;
        if (!((k - i) & 1))
        {
            long long t = (k - i) / 2;
            long long x = b + 1 - i - t;
            long long y = s - i - 2 * t;
            t -= 1;
            long long z = nCr_mod(b - 1, t, mod) * nCr_mod(x + i, x, mod) % mod;
            ans = (ans + z * nHr_mod(t + 2, y, mod)) % mod;
        }
        k++;
        if (!((k - i) & 1))
        {
            long long t = (k - i) / 2;
            long long x = b + 1 - i - t;
            long long y = s - i - 2 * t;
            t -= 2;
            long long z = nCr_mod(b - 1, t, mod) * nCr_mod(x + i, x, mod) % mod;
            ans = (ans + z * nHr_mod(t + 2, y, mod)) % mod;
        }
        k -= 2;
    }
    printf("%lld\n", ans);
    return 0;
}
0