結果

問題 No.2113 Distance Sequence 1.5
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-07 23:40:10
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 7,623 ms
コンパイル使用メモリ 156,056 KB
実行使用メモリ 177,328 KB
最終ジャッジ日時 2023-11-07 23:40:21
合計ジャッジ時間 10,751 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
32,548 KB
testcase_01 AC 78 ms
32,548 KB
testcase_02 AC 76 ms
32,548 KB
testcase_03 AC 77 ms
32,548 KB
testcase_04 AC 76 ms
32,548 KB
testcase_05 AC 76 ms
32,548 KB
testcase_06 AC 76 ms
32,548 KB
testcase_07 AC 77 ms
32,548 KB
testcase_08 AC 78 ms
32,536 KB
testcase_09 AC 77 ms
32,536 KB
testcase_10 AC 77 ms
32,536 KB
testcase_11 AC 76 ms
32,536 KB
testcase_12 AC 76 ms
32,536 KB
testcase_13 AC 77 ms
32,536 KB
testcase_14 AC 77 ms
32,536 KB
testcase_15 AC 76 ms
32,536 KB
testcase_16 AC 76 ms
32,536 KB
testcase_17 AC 76 ms
32,536 KB
testcase_18 AC 76 ms
32,536 KB
testcase_19 AC 76 ms
32,548 KB
testcase_20 AC 75 ms
32,548 KB
testcase_21 AC 76 ms
32,548 KB
testcase_22 AC 76 ms
32,548 KB
testcase_23 AC 77 ms
32,548 KB
testcase_24 AC 75 ms
177,328 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (99 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, m, k) = (c[0], c[1], c[2]);
        WriteLine(Distance(n, m, k));
    }
    static long Distance(long n, long m, long k)
    {
        var mod = 998_244_353;
        if (m <= k)
        {
            return Exp(m, n * 2, mod);
        }
        var upmin = (m - k) % mod;
        return ((Exp(k, n * 2, mod) - Exp(k - 1, n * 2, mod) + mod) % mod * upmin % mod + Exp(k, n * 2, mod)) % mod;
    }
    static long Exp(long n, long k, int mod)
    {
        n %= mod;
        if (k == 0) return 1;
        if (k == 1) return n;
        var half = Exp(n, k / 2, mod);
        var result = half * half % mod;
        return ((k % 2) == 0) ? result : (result * n % mod);
    }
}
0