結果

問題 No.2409 Strange Werewolves
ユーザー AngrySadEightAngrySadEight
提出日時 2023-07-11 13:57:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 80,980 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-04-18 00:51:58
合計ジャッジ時間 11,350 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 505 ms
12,544 KB
testcase_01 AC 509 ms
12,544 KB
testcase_02 AC 504 ms
12,544 KB
testcase_03 AC 510 ms
12,672 KB
testcase_04 AC 506 ms
12,672 KB
testcase_05 AC 513 ms
12,544 KB
testcase_06 AC 515 ms
12,524 KB
testcase_07 AC 502 ms
12,544 KB
testcase_08 AC 507 ms
12,584 KB
testcase_09 AC 504 ms
12,544 KB
testcase_10 AC 508 ms
12,672 KB
testcase_11 AC 505 ms
12,544 KB
testcase_12 AC 505 ms
12,544 KB
testcase_13 AC 504 ms
12,544 KB
testcase_14 AC 514 ms
12,544 KB
testcase_15 AC 512 ms
12,672 KB
testcase_16 AC 508 ms
12,672 KB
testcase_17 AC 507 ms
12,572 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;
    }
    vector<ll> fact_inv(600005);
    for (ll i = 0; i < 600005; i++) {
        fact_inv[i] = inv(fact[i], mod);
    }

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