結果

問題 No.2544 Many RMQ Problems
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-24 23:42:01
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 2,677 bytes
コンパイル時間 9,317 ms
コンパイル使用メモリ 158,156 KB
実行使用メモリ 188,300 KB
最終ジャッジ日時 2023-11-24 23:42:16
合計ジャッジ時間 14,531 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
32,548 KB
testcase_01 AC 76 ms
32,548 KB
testcase_02 AC 77 ms
32,548 KB
testcase_03 AC 216 ms
40,928 KB
testcase_04 AC 200 ms
40,028 KB
testcase_05 AC 188 ms
39,344 KB
testcase_06 AC 205 ms
40,324 KB
testcase_07 AC 136 ms
36,132 KB
testcase_08 AC 102 ms
34,212 KB
testcase_09 AC 76 ms
32,548 KB
testcase_10 AC 78 ms
32,548 KB
testcase_11 AC 77 ms
32,548 KB
testcase_12 AC 77 ms
32,548 KB
testcase_13 AC 76 ms
32,548 KB
testcase_14 AC 77 ms
32,548 KB
testcase_15 AC 77 ms
32,548 KB
testcase_16 AC 76 ms
32,548 KB
testcase_17 AC 76 ms
32,548 KB
testcase_18 AC 77 ms
32,548 KB
testcase_19 AC 215 ms
40,928 KB
testcase_20 AC 216 ms
40,928 KB
testcase_21 AC 214 ms
40,928 KB
testcase_22 AC 215 ms
40,928 KB
testcase_23 AC 214 ms
40,928 KB
testcase_24 AC 77 ms
32,548 KB
testcase_25 AC 76 ms
32,548 KB
testcase_26 AC 216 ms
40,928 KB
testcase_27 AC 78 ms
32,548 KB
testcase_28 AC 215 ms
188,300 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (98 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

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, q) = (c[0], c[1]);
        WriteLine(Many(n, q));
    }
    static long Many(int n, int q)
    {
        var mod = 998_244_353;
        var ncr = new NCR(n + 1, mod);
        var ans = 0L;
        var cnt = ncr.Exp((long)n * (n + 1) / 2, q - 1) * q % mod;
        for (var a = 1; a <= n; ++a)
        {
            ans = (ans + ncr.Fact(n) % mod * (n + 1) % mod * (n - a + 1) % mod * ncr.Inverse(a + 1) % mod * cnt % mod) % mod;
        }
        return 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];
        }
        public long Inverse(int n)
        {
            return (long)revFacts[n] * facts[n - 1] % mod;
        }
    }
}
0