結果

問題 No.2409 Strange Werewolves
ユーザー sbriasbria
提出日時 2023-08-12 11:57:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 64,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-30 01:55:12
合計ジャッジ時間 1,279 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using ll = long long;

ll mod_pow( ll a, ll n, ll mod )
{
    ll r = 1;
    while (n > 0) {
        if (n & 1) r = r * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return r % mod;
}

ll combination( ll n, ll r, ll mod )
{
    ll x = 1, y = 1;
    for (ll i = 0; i < r; i++) {
        x = x * ( n - i ) % mod;
        y = y * ( i + 1 ) % mod;
    }
    return x * mod_pow( y, mod - 2, mod ) % mod;
}

ll factorial( ll n, ll mod )
{
    ll a = 1;
    for (ll i = 2; i <= n; i++) {
        a = a * i % mod;
    }
    return a;
}

int main( void )
{
    ll X, Y, Z, W;
    X = Y = Z = W = 1;
    std::cin >> X >> Y >> Z >> W;
    const ll mod = 998244353;

    ll a = (Z != 0) ? combination( X, Z, mod ) : X;
    ll b = (W != 0) ? combination( Y, W, mod ) : Y;
    ll c = factorial( X + Y - Z - W - 1, mod );

    ll ans = a * b % mod * c % mod;
    std::cout << ans;
    
    return 0;
}
0