結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー 👑 kakel-sankakel-san
提出日時 2022-11-25 22:12:46
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,349 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 113,932 KB
実行使用メモリ 27,948 KB
最終ジャッジ日時 2024-04-10 03:21:28
合計ジャッジ時間 3,260 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
23,516 KB
testcase_01 AC 24 ms
23,768 KB
testcase_02 AC 23 ms
23,504 KB
testcase_03 AC 22 ms
21,692 KB
testcase_04 AC 24 ms
23,884 KB
testcase_05 AC 23 ms
23,632 KB
testcase_06 AC 22 ms
23,508 KB
testcase_07 AC 23 ms
23,724 KB
testcase_08 AC 23 ms
23,644 KB
testcase_09 AC 23 ms
23,508 KB
testcase_10 AC 25 ms
23,516 KB
testcase_11 AC 25 ms
23,600 KB
testcase_12 AC 24 ms
23,900 KB
testcase_13 AC 25 ms
23,728 KB
testcase_14 AC 25 ms
23,768 KB
testcase_15 AC 24 ms
21,560 KB
testcase_16 AC 25 ms
25,820 KB
testcase_17 AC 25 ms
24,032 KB
testcase_18 AC 26 ms
25,812 KB
testcase_19 AC 25 ms
23,672 KB
testcase_20 AC 24 ms
23,764 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 24 ms
23,600 KB
testcase_29 WA -
testcase_30 AC 24 ms
23,640 KB
testcase_31 AC 23 ms
21,808 KB
testcase_32 AC 24 ms
21,688 KB
testcase_33 AC 24 ms
23,392 KB
testcase_34 AC 24 ms
23,648 KB
testcase_35 AC 23 ms
23,624 KB
testcase_36 AC 24 ms
25,924 KB
testcase_37 AC 24 ms
23,516 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
{
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = long.Parse(ReadLine());
        var m = int.Parse(ReadLine());
        var mod = 998_244_353;
        var ncr = new NCR(m, mod);
        var res = ncr.Exp(2, n);
        var tmp = 1L;
        for (var i = 0; i < m; ++i)
        {
            res = (res - tmp * ncr.RevFact(i) % mod + mod) % mod;
            tmp = tmp * (n - i) % mod;
        }
        WriteLine(res);
    }
    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;
        }
        public long Calc2(long 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