結果

問題 No.2023 Tiling is Fun
ユーザー 👑 kakel-sankakel-san
提出日時 2022-07-29 21:51:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,976 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 65,912 KB
実行使用メモリ 24,860 KB
最終ジャッジ日時 2023-09-26 20:33:24
合計ジャッジ時間 3,492 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
23,824 KB
testcase_01 AC 64 ms
22,252 KB
testcase_02 AC 61 ms
21,828 KB
testcase_03 AC 63 ms
21,944 KB
testcase_04 AC 60 ms
23,864 KB
testcase_05 AC 62 ms
23,956 KB
testcase_06 AC 62 ms
21,884 KB
testcase_07 AC 65 ms
24,472 KB
testcase_08 AC 65 ms
23,976 KB
testcase_09 AC 66 ms
24,272 KB
testcase_10 AC 66 ms
22,268 KB
testcase_11 AC 61 ms
24,000 KB
testcase_12 AC 60 ms
21,780 KB
testcase_13 AC 60 ms
21,900 KB
testcase_14 AC 64 ms
21,948 KB
testcase_15 AC 64 ms
21,944 KB
testcase_16 AC 63 ms
22,048 KB
testcase_17 AC 68 ms
24,860 KB
testcase_18 AC 68 ms
24,852 KB
testcase_19 AC 66 ms
22,292 KB
権限があれば一括ダウンロードができます

ソースコード

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 void Main()
    {
        var c = NList;
        var mod = 998_244_353;
        var ncr = new NCR(c[0] + c[1] - 2, mod);
        WriteLine(ncr.Calc(c[0] + c[1] - 2, c[0] - 1));
    }
    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;
        }
        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 int Calc(int n, int r)
        {
            if (r == 0 || r == n) return 1;
            if (r == 1) return n;
            return (int)(((long)facts[n] * revFacts[r] % mod) * revFacts[n - r] % mod);
        }
        public int Calc2(int n, int r)
        {
            var tmp = 1L;
            for (var i = 0; i < r; ++i)
            {
                tmp = tmp * (n - i) % mod;
            }
            return (int)(tmp * revFacts[r] % mod);
        }
        public int Fact(int n)
        {
            return facts[n];
        }
    }
}
0