結果

問題 No.2409 Strange Werewolves
ユーザー AngrySadEightAngrySadEight
提出日時 2023-07-11 14:01:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 693 ms
コンパイル使用メモリ 79,992 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-04-18 00:51:46
合計ジャッジ時間 1,729 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,064 KB
testcase_01 AC 14 ms
7,928 KB
testcase_02 AC 14 ms
8,036 KB
testcase_03 AC 14 ms
8,048 KB
testcase_04 AC 15 ms
7,808 KB
testcase_05 AC 14 ms
7,936 KB
testcase_06 AC 15 ms
7,864 KB
testcase_07 AC 13 ms
7,888 KB
testcase_08 AC 14 ms
8,064 KB
testcase_09 AC 15 ms
8,064 KB
testcase_10 AC 14 ms
8,028 KB
testcase_11 AC 13 ms
8,036 KB
testcase_12 AC 14 ms
7,864 KB
testcase_13 AC 14 ms
8,064 KB
testcase_14 AC 13 ms
7,936 KB
testcase_15 AC 14 ms
7,936 KB
testcase_16 AC 14 ms
7,932 KB
testcase_17 AC 15 ms
7,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll my_pow(ll x, ll n, ll mod) {
    ll ret;
    if (n == 0) {
        ret = 1;
    } else if (n % 2 == 1) {
        ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod;
    } else {
        ret = my_pow((x * x) % mod, n / 2, mod);
    }
    return ret;
}

ll inv(ll x, ll mod) { return my_pow(x, mod - 2, mod); }

ll mod = 998244353;

int main() {
    ll X, Y, Z, W;
    cin >> X >> Y >> Z >> W;

    vector<ll> fact(600005);
    fact[0] = 1;
    for (ll i = 0; i < 600004; i++) {
        fact[i + 1] = (fact[i] * (i + 1)) % mod;
    }

    if (Z == 0) {
        swap(X, Y);
        swap(Z, W);
    }
    ll ans =
        (fact[X] * ((inv(fact[X - Z], mod) * inv(fact[Z], mod)) % mod)) % mod;
    ans = (ans * Y) % mod;
    ans = (ans * fact[X + Y - Z - W - 1]) % mod;
    cout << ans << endl;
}
0