結果

問題 No.2807 Have Another Go (Easy)
ユーザー 👑 kakel-sankakel-san
提出日時 2024-07-16 00:05:05
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 233 ms / 3,000 ms
コード長 2,864 bytes
コンパイル時間 8,089 ms
コンパイル使用メモリ 167,308 KB
実行使用メモリ 186,560 KB
最終ジャッジ日時 2024-07-16 00:05:24
合計ジャッジ時間 17,571 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
30,720 KB
testcase_01 AC 211 ms
47,244 KB
testcase_02 AC 155 ms
42,192 KB
testcase_03 AC 141 ms
40,132 KB
testcase_04 AC 129 ms
38,452 KB
testcase_05 AC 181 ms
44,296 KB
testcase_06 AC 187 ms
43,900 KB
testcase_07 AC 76 ms
32,768 KB
testcase_08 AC 107 ms
35,448 KB
testcase_09 AC 112 ms
36,880 KB
testcase_10 AC 142 ms
39,860 KB
testcase_11 AC 221 ms
48,784 KB
testcase_12 AC 220 ms
48,256 KB
testcase_13 AC 233 ms
48,528 KB
testcase_14 AC 225 ms
48,256 KB
testcase_15 AC 225 ms
48,244 KB
testcase_16 AC 220 ms
48,532 KB
testcase_17 AC 220 ms
48,276 KB
testcase_18 AC 228 ms
48,656 KB
testcase_19 AC 223 ms
48,408 KB
testcase_20 AC 220 ms
48,528 KB
testcase_21 AC 220 ms
48,404 KB
testcase_22 AC 220 ms
48,536 KB
testcase_23 AC 223 ms
48,276 KB
testcase_24 AC 231 ms
48,532 KB
testcase_25 AC 223 ms
48,532 KB
testcase_26 AC 222 ms
48,396 KB
testcase_27 AC 221 ms
48,528 KB
testcase_28 AC 221 ms
48,264 KB
testcase_29 AC 228 ms
48,256 KB
testcase_30 AC 220 ms
48,920 KB
testcase_31 AC 66 ms
31,488 KB
testcase_32 AC 64 ms
31,224 KB
testcase_33 AC 66 ms
31,360 KB
testcase_34 AC 64 ms
32,984 KB
testcase_35 AC 66 ms
31,488 KB
testcase_36 AC 63 ms
30,836 KB
testcase_37 AC 67 ms
31,616 KB
testcase_38 AC 65 ms
31,616 KB
testcase_39 AC 62 ms
30,976 KB
testcase_40 AC 73 ms
32,640 KB
testcase_41 AC 69 ms
31,616 KB
testcase_42 AC 64 ms
31,616 KB
testcase_43 AC 63 ms
31,232 KB
testcase_44 AC 64 ms
31,488 KB
testcase_45 AC 66 ms
186,560 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (99 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.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();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    static int[] LList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => int.Parse(ReadLine())).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m, k) = (c[0], c[1], c[2]);
        var a = NList;
        if (n < 7) WriteLine(string.Join("\n", GoShort(n, m, k, a)));
        else WriteLine(string.Join("\n", Go(n, m, k, a)));
    }
    static long[] Go(int n, int m, int k, int[] a)
    {
        var mod = 998_244_353;
        var dp1 = new long[n * 2 + 1];
        var dp2 = new long[n * 2 + 1];
        dp1[0] = 1;
        for (var i = 0; i + 1 < dp1.Length; ++i)
        {
            for (var p = 1; p <= 6; ++p)
            {
                if (i + p >= dp1.Length) dp1[^1] = (dp1[^1] + dp1[i]) % mod;
                else dp1[i + p] = (dp1[i + p] + dp1[i]) % mod;
            }
        }
        dp2[^1] = 1;
        dp2[^2] = 5;
        dp2[^3] = 4;
        dp2[^4] = 3;
        dp2[^5] = 2;
        dp2[^6] = 1;
        for (var i = dp2.Length - 1; i > 0; --i)
        {
            for (var p = 1; p <= 6; ++p)
            {
                if (i - p < 0) dp2[0] = (dp2[0] + dp2[i]) % mod;
                else dp2[i - p] = (dp2[i - p] + dp2[i]) % mod;
            }
        }
        var ans = new long[k];
        for (var i = 0; i < k; ++i)
        {
            ans[i] = (dp1[a[i]] * dp2[a[i]] % mod + dp1[n + a[i]] * dp2[n + a[i]] % mod
                - dp1[a[i]] * dp1[n] % mod * dp2[n + a[i]] % mod + mod) % mod;
        }
        return ans;
    }
    static long[] GoShort(int n, int m, int k, int[] a)
    {
        var ans = new long[k];
        var mod = 998_244_353;
        for (var i = 0; i < k; ++i)
        {
            var dp1 = new long[n * 2 + 1];
            var dp2 = new long[n * 2 + 1];
            dp1[0] = 1;
            for (var j = 0; j + 1 < dp1.Length; ++j)
            {
                for (var p = 1; p <= 6; ++p)
                {
                    if (j + p >= dp1.Length) dp1[^1] = (dp1[^1] + dp1[j]) % mod;
                    else if ((j + p) % n == a[i]) dp2[j + p] = (dp2[j + p] + dp1[j]) % mod;
                    else dp1[j + p] = (dp1[j + p] + dp1[j]) % mod;
                    if (j + p >= dp2.Length) dp2[^1] = (dp2[^1] + dp2[j]) % mod;
                    else dp2[j + p] = (dp2[j + p] + dp2[j]) % mod;
                }
            }
            ans[i] = dp2[^1];
        }
        return ans;
    }
}
0