結果

問題 No.1552 Simple Dice Game
ユーザー 👑 kakel-sankakel-san
提出日時 2024-03-08 00:27:35
言語 C#
(.NET 8.0.203)
結果
TLE  
実行時間 -
コード長 2,091 bytes
コンパイル時間 15,349 ms
コンパイル使用メモリ 158,428 KB
実行使用メモリ 179,928 KB
最終ジャッジ日時 2024-03-08 00:28:33
合計ジャッジ時間 57,811 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
32,548 KB
testcase_01 AC 74 ms
32,548 KB
testcase_02 AC 73 ms
32,548 KB
testcase_03 TLE -
testcase_04 AC 73 ms
32,548 KB
testcase_05 AC 73 ms
32,548 KB
testcase_06 AC 77 ms
32,548 KB
testcase_07 AC 76 ms
32,548 KB
testcase_08 AC 78 ms
32,548 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 951 ms
32,804 KB
testcase_13 TLE -
testcase_14 AC 1,573 ms
32,804 KB
testcase_15 AC 1,935 ms
32,804 KB
testcase_16 AC 335 ms
32,804 KB
testcase_17 AC 493 ms
32,804 KB
testcase_18 AC 2,413 ms
32,932 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (145 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 long NN => long.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        WriteLine(Dice(n, m));
    }
    static long Dice(long n, long m)
    { checked{
        var ans = 0L;
        var mod = 998_244_353;
        var rev2 = 499_122_177;
        var nc = n % mod;
        var revn = Exp(nc, mod - 2, mod);
        for (var i = 1; i < m; ++i)
        {
            if (i == 1)
            {
                var tb = (Exp(i + 1, n - 1, mod) - Exp(i, n - 1, mod) + mod) % mod * nc % mod;
                var count = tb * 2 % mod;
                var add = (tb * (i + 2) % mod * (m - i) % mod + count % mod * (m - 2) % mod * (m - 1) % mod * rev2 % mod) * i % mod;
                ans = (ans + add) % mod;
            }
            else
            {
                var tb = (Exp(i + 1, n - 1, mod) - Exp(i, n - 1, mod) + mod) % mod * nc % mod;
                var mid = (Exp(i + 1, n - 1, mod) - Exp(i, n - 1, mod) * 2 + Exp(i - 1, n - 1, mod) + mod + mod) % mod * nc % mod;
                var count = (tb * 2 + mid * (i - 1) % mod) % mod;
                var add = ((tb * (i + 2) % mod + (i * (i + 1L) % mod * rev2 % mod - 1 + mod) % mod * mid % mod) % mod * (m - i) % mod
                    + count % mod * (m - i - 1) % mod * (m - i) % mod * rev2 % mod) * i % mod;
                ans = (ans + add) % mod;
            }
        }
        return ans;
    } }
    static long Exp(long n, long p, int mod)
    {
        long _n = n % mod;
        var _p = p;
        var result = 1L;
        if ((_p & 1) == 1) result *= _n;
        while (_p > 0)
        {
            _n = _n * _n % mod;
            _p >>= 1;
            if ((_p & 1) == 1) result = result * _n % mod;
        }
        return result;
    }
}
0