結果

問題 No.2141 Enumeratest
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-15 23:53:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 2,668 bytes
コンパイル時間 1,079 ms
コンパイル使用メモリ 68,276 KB
実行使用メモリ 29,068 KB
最終ジャッジ日時 2023-09-15 23:53:55
合計ジャッジ時間 7,312 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
19,700 KB
testcase_01 AC 59 ms
21,804 KB
testcase_02 AC 72 ms
23,032 KB
testcase_03 AC 96 ms
29,068 KB
testcase_04 AC 153 ms
27,112 KB
testcase_05 AC 116 ms
21,976 KB
testcase_06 AC 60 ms
21,908 KB
testcase_07 AC 63 ms
21,964 KB
testcase_08 AC 75 ms
24,180 KB
testcase_09 AC 71 ms
25,144 KB
testcase_10 AC 82 ms
25,748 KB
testcase_11 AC 93 ms
28,384 KB
testcase_12 AC 61 ms
21,800 KB
testcase_13 AC 70 ms
22,976 KB
testcase_14 AC 93 ms
28,368 KB
testcase_15 AC 80 ms
25,196 KB
testcase_16 AC 85 ms
26,324 KB
testcase_17 AC 120 ms
27,852 KB
testcase_18 AC 117 ms
25,388 KB
testcase_19 AC 139 ms
27,116 KB
testcase_20 AC 118 ms
26,444 KB
testcase_21 AC 121 ms
26,448 KB
testcase_22 AC 104 ms
25,540 KB
testcase_23 AC 85 ms
25,312 KB
testcase_24 AC 107 ms
28,680 KB
testcase_25 AC 73 ms
21,664 KB
testcase_26 AC 113 ms
21,936 KB
testcase_27 AC 117 ms
25,856 KB
testcase_28 AC 126 ms
25,560 KB
testcase_29 AC 97 ms
22,744 KB
testcase_30 AC 137 ms
28,780 KB
testcase_31 AC 114 ms
27,028 KB
testcase_32 AC 125 ms
26,368 KB
testcase_33 AC 108 ms
26,364 KB
testcase_34 AC 119 ms
27,260 KB
testcase_35 AC 65 ms
23,800 KB
testcase_36 AC 124 ms
23,940 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 int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var mod = 998_244_353;
        var ncr = new NCR(m, mod);
        var ans = 1L;
        var cnt = m;
        for (var i = 0; i < n; ++i)
        {
            var take = m / n + (i < m % n ? 1 : 0);
            // WriteLine($"{i} {take}");
            ans = ans * ncr.Calc(cnt, take) % mod;
            cnt -= take;
        }
        WriteLine(ans);
    }
    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