結果
| 問題 |
No.2409 Strange Werewolves
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2023-08-11 21:56:43 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 1,354 bytes |
| コンパイル時間 | 402 ms |
| コンパイル使用メモリ | 31,360 KB |
| 実行使用メモリ | 11,264 KB |
| 最終ジャッジ日時 | 2024-11-18 16:10:38 |
| 合計ジャッジ時間 | 1,353 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 |
ソースコード
#include <stdio.h>
long long power_mod (long long a, long long b, long long mod_num) {
long long ans = 1LL;
if (b > 0LL) {
ans = power_mod(a, b/2LL, mod_num);
ans = (ans * ans) % mod_num;
if (b%2LL == 1LL) {
ans = (ans * (a % mod_num)) % mod_num;
}
}
return ans;
}
int main () {
int x = 0;
int y = 0;
int z = 0;
int w = 0;
int res = 0;
long long ans = 0LL;
long long mod_num = 998244353LL;
long long fact[600001] = {};
long long invf[600001] = {};
res = scanf("%d", &x);
res = scanf("%d", &y);
res = scanf("%d", &z);
res = scanf("%d", &w);
fact[0] = 1LL;
for (int i = 0; i < x+y; i++) {
fact[i+1] = fact[i];
fact[i+1] *= (long long)(i+1);
fact[i+1] %= mod_num;
}
invf[x+y] = power_mod(fact[x+y], mod_num-2LL, mod_num);
for (int i = x+y; i > 0; i--) {
invf[i-1] = invf[i];
invf[i-1] *= (long long)i;
invf[i-1] %= mod_num;
}
ans = fact[x];
ans *= invf[z];
ans %= mod_num;
ans *= fact[y];
ans %= mod_num;
ans *= invf[w];
ans %= mod_num;
ans *= fact[x+y-1-z-w];
ans %= mod_num;
if (z == 0) {
ans *= invf[x-1];
ans %= mod_num;
ans *= invf[y-w];
ans %= mod_num;
} else {
ans *= invf[y-1];
ans %= mod_num;
ans *= invf[x-z];
ans %= mod_num;
}
printf("%lld\n", ans);
return 0;
}
chro_96