結果

問題 No.2058 Binary String
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-09 14:19:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 2,449 bytes
コンパイル時間 1,282 ms
コンパイル使用メモリ 66,112 KB
実行使用メモリ 24,960 KB
最終ジャッジ日時 2023-10-09 14:19:53
合計ジャッジ時間 6,084 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
23,988 KB
testcase_01 AC 57 ms
21,824 KB
testcase_02 AC 82 ms
22,864 KB
testcase_03 AC 55 ms
21,856 KB
testcase_04 AC 56 ms
21,864 KB
testcase_05 AC 56 ms
19,828 KB
testcase_06 AC 62 ms
22,040 KB
testcase_07 AC 220 ms
24,684 KB
testcase_08 AC 81 ms
21,932 KB
testcase_09 AC 227 ms
22,864 KB
testcase_10 AC 119 ms
22,064 KB
testcase_11 AC 94 ms
21,804 KB
testcase_12 AC 147 ms
22,148 KB
testcase_13 AC 125 ms
24,012 KB
testcase_14 AC 108 ms
21,896 KB
testcase_15 AC 111 ms
21,872 KB
testcase_16 AC 109 ms
21,984 KB
testcase_17 AC 123 ms
19,912 KB
testcase_18 AC 64 ms
23,988 KB
testcase_19 AC 225 ms
24,864 KB
testcase_20 AC 199 ms
22,508 KB
testcase_21 AC 230 ms
22,960 KB
testcase_22 AC 232 ms
24,960 KB
testcase_23 AC 246 ms
22,792 KB
testcase_24 AC 229 ms
23,056 KB
testcase_25 AC 242 ms
22,804 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();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, k) = (c[0], c[1]);
        var mod = 998_244_353;
        var ncr = new NCR(n, mod);
        var ans = 0L;
        for (var i = 1; i < n; ++i)
        {
            ans = (ans + ncr.Exp(i, k) * ncr.Calc(n - 1, i)) % mod;
        }
        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