結果

問題 No.2409 Strange Werewolves
ユーザー SSRSSSRS
提出日時 2023-08-11 21:28:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 852 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 168,884 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-29 12:17:03
合計ジャッジ時間 5,014 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
  int X, Y, Z, W;
  cin >> X >> Y >> Z >> W;
  if (W == 0){
    swap(X, Y);
    swap(Z, W);
  }
  if (W == Y){
    long long ans = 1;
    for (int i = X; i > Z; i++){
      ans *= i;
      ans %= MOD;
    }
    cout << ans << endl;
  } else {
    vector<long long> inv(Y + 1);
    inv[1] = 1;
    for (int i = 2; i <= Y; i++){
      inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    }
    long long ans = X;
    for (int i = 1; i <= Y; i++){
      ans *= i;
      ans %= MOD;
    }
    for (int i = 1; i <= W; i++){
      ans *= inv[i];
      ans %= MOD;
    }
    for (int i = 1; i <= Y - W; i++){
      ans *= inv[i];
      ans %= MOD;
    }
    for (int i = 1; i <= X + Y - W - 1; i++){
      ans *= i;
      ans %= MOD;
    }
    cout << ans << endl;
  }
}
0