結果
問題 | No.2409 Strange Werewolves |
ユーザー |
![]() |
提出日時 | 2023-08-12 08:05:38 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 1,842 bytes |
コンパイル時間 | 3,804 ms |
コンパイル使用メモリ | 118,660 KB |
実行使用メモリ | 28,892 KB |
最終ジャッジ日時 | 2024-11-19 07:10:27 |
合計ジャッジ時間 | 5,130 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using static System.Math; using System; public class Hello { public static int MOD = 998244353; static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var x = int.Parse(line[0]); var y = int.Parse(line[1]); var z = int.Parse(line[2]); var w = int.Parse(line[3]); if (w == 0) getAns(x, y, z); else getAns(y, x, w); } static void getAns(int x, int y, int z) { var max = x + y + z; var md = new Modulo(max); long ans = md.Fac(x - z + y - 1); var t = md.Ncr(x, x - z); ans *= t; ans %= MOD; ans *= y; ans %= MOD; Console.WriteLine(ans); } class Modulo { private int MOD = Hello.MOD; private readonly int[] m_facs; public int Mul(int a, int b) => (int)(BigMul(a, b) % MOD); public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) m_facs[i] = Mul(m_facs[i - 1], i); } public int Fac(int n) => m_facs[n]; public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2)); public int Ncr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } }