結果

問題 No.2409 Strange Werewolves
ユーザー 👑 kakel-sankakel-san
提出日時 2023-08-11 21:53:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 2,713 bytes
コンパイル時間 2,332 ms
コンパイル使用メモリ 108,672 KB
実行使用メモリ 23,040 KB
最終ジャッジ日時 2024-04-29 12:47:40
合計ジャッジ時間 2,312 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
18,816 KB
testcase_01 AC 28 ms
19,072 KB
testcase_02 AC 28 ms
18,944 KB
testcase_03 AC 52 ms
22,656 KB
testcase_04 AC 50 ms
22,784 KB
testcase_05 AC 39 ms
20,480 KB
testcase_06 AC 52 ms
22,784 KB
testcase_07 AC 51 ms
23,040 KB
testcase_08 AC 40 ms
20,864 KB
testcase_09 AC 41 ms
20,864 KB
testcase_10 AC 34 ms
19,456 KB
testcase_11 AC 29 ms
18,968 KB
testcase_12 AC 34 ms
19,584 KB
testcase_13 AC 39 ms
20,608 KB
testcase_14 AC 42 ms
21,248 KB
testcase_15 AC 41 ms
20,992 KB
testcase_16 AC 38 ms
20,352 KB
testcase_17 AC 29 ms
18,992 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (x, y, z, w) = (c[0], c[1], c[2], c[3]);
        var mod = 998_244_353;
        var ncr = new NCR(x + y, mod);
        if (z == 0)
        {
            WriteLine(ncr.Calc(x - 1 + y - w, x - 1) * ncr.Fact(x) % mod * ncr.Calc(y, w) % mod * ncr.Fact(y - w) % mod);
        }
        else
        {
            WriteLine(ncr.Calc(x - z + y - 1, y - 1) * ncr.Fact(y) % mod * ncr.Calc(x, z) % mod * ncr.Fact(x - z) % mod);
        }
    }
    class NCR
    {
        int[] facts;
        int[] revFacts;
        int mod;
        public NCR(int n, int mod)
        {
            facts = new int[n + 1];
            revFacts = new int[n + 1];
            this.mod = mod;
            facts[0] = 1;
            var tmp = 1L;
            for (var i = 1; i <= n; ++i)
            {
                tmp = (tmp * i) % mod;
                facts[i] = (int)tmp;
            }
            tmp = Exp(facts[n], mod - 2);
            revFacts[n] = (int)tmp;
            for (var i = n; i > 1; --i)
            {
                tmp = (tmp * i) % mod;
                revFacts[i - 1] = (int)tmp;
            }
            revFacts[0] = 1;
        }
        public long Exp(long n, long k)
        {
            n = n % mod;
            if (k == 0) return 1;
            if (k == 1) return n;
            var half = Exp(n, k / 2);
            var result = (half * half) % mod;
            return ((k % 2) == 0) ? result : ((result * n) % mod);
        }
        public long Calc(int n, int r)
        {
            return (long)facts[n] * revFacts[r] % mod * revFacts[n - r] % mod;
        }
        /// <summary>nが大きくrが小さい場合の計算</summary>
        public long Calc2(int n, int r)
        {
            var tmp = 1L;
            for (var i = 0; i < r; ++i)
            {
                tmp = tmp * (n - i) % mod;
            }
            return tmp * revFacts[r] % mod;
        }
        public long NPR(int n, int r)
        {
            return (long)facts[n] * revFacts[r] % mod;
        }
        public long Fact(int n)
        {
            return facts[n];
        }
        public long RevFact(int n)
        {
            return revFacts[n];
        }
    }
}
0