結果

問題 No.2530 Yellow Cards
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-03 22:22:18
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,557 ms / 2,000 ms
コード長 1,355 bytes
コンパイル時間 7,570 ms
コンパイル使用メモリ 158,216 KB
実行使用メモリ 198,712 KB
最終ジャッジ日時 2023-11-03 22:22:44
合計ジャッジ時間 23,593 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
32,356 KB
testcase_01 AC 64 ms
32,376 KB
testcase_02 AC 65 ms
32,828 KB
testcase_03 AC 67 ms
32,868 KB
testcase_04 AC 65 ms
32,376 KB
testcase_05 AC 71 ms
32,828 KB
testcase_06 AC 65 ms
32,436 KB
testcase_07 AC 1,557 ms
56,272 KB
testcase_08 AC 1,523 ms
56,260 KB
testcase_09 AC 1,531 ms
56,280 KB
testcase_10 AC 1,552 ms
56,288 KB
testcase_11 AC 1,526 ms
56,304 KB
testcase_12 AC 1,540 ms
56,264 KB
testcase_13 AC 1,523 ms
56,252 KB
testcase_14 AC 1,094 ms
56,188 KB
testcase_15 AC 749 ms
56,048 KB
testcase_16 AC 747 ms
56,064 KB
testcase_17 AC 1,163 ms
56,176 KB
testcase_18 AC 517 ms
56,040 KB
testcase_19 AC 172 ms
46,404 KB
testcase_20 AC 229 ms
198,712 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (114 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 long[] NList => ReadLine().Split().Select(long.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 rev = Exp(n, mod - 2, mod);
        var dp = new long[n + 1];
        dp[0] = 1;
        var ans = n;
        for (var i = 0; i < k; ++i)
        {
            var ndp = new long[n + 1];
            for (var j = 0; j < dp.Length; ++j)
            {
                if (j > 0)
                {
                    ndp[j - 1] = (ndp[j - 1] + dp[j] * j % mod * rev) % mod;
                    ans = (ans + dp[j] * j % mod * rev) % mod;
                }
                if (j < n) ndp[j + 1] = (ndp[j + 1] + dp[j] * (n - j) % mod * rev) % mod;
            }
            dp = ndp;
        }
        WriteLine(ans);
    }
    static long Exp(long n, long k, int mod)
    {
        if (k == 0) return 1;
        if (k == 1) return n % mod;
        var half = Exp(n, k / 2, mod);
        var result = (half * half) % mod;
        return ((k % 2) == 0) ? result : ((result * n) % mod);
    }
}
0