結果

問題 No.2807 Have Another Go (Easy)
ユーザー tobisatistobisatis
提出日時 2024-07-12 23:05:12
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 4,757 bytes
コンパイル時間 10,425 ms
コンパイル使用メモリ 169,356 KB
実行使用メモリ 211,804 KB
最終ジャッジ日時 2024-07-12 23:06:39
合計ジャッジ時間 83,631 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
30,592 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 178 ms
39,808 KB
testcase_37 AC 86 ms
32,768 KB
testcase_38 AC 570 ms
54,752 KB
testcase_39 AC 83 ms
32,384 KB
testcase_40 AC 414 ms
54,656 KB
testcase_41 AC 573 ms
54,784 KB
testcase_42 AC 526 ms
54,784 KB
testcase_43 AC 391 ms
54,500 KB
testcase_44 AC 439 ms
54,504 KB
testcase_45 AC 270 ms
211,804 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (89 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 #

namespace AtCoder;

#nullable enable

using System.Numerics;

readonly struct Matrix : IAdditionOperators<Matrix, Matrix, Matrix>, IMultiplyOperators<Matrix, Matrix, Matrix>
{
    long[,] V { get; init; }
    public long this[int i, int j] { get => V[i, j]; set { V[i, j] = Mod(value); } }
    public int X => V.GetLength(0);
    public int Y => V.GetLength(1);

    const int p = 998244353;
    static long Mod(long v)
    {
        var res = v % p;
        if (res < 0) res += p;
        return res;
    }

    public Matrix(int[,] matrix)
    {
        var (x, y) = (matrix.GetLength(0), matrix.GetLength(1));
        var v = new long[x, y];
        for (var i = 0; i < x; i++) for (var j = 0; j < y; j++) v[i, j] = Mod(matrix[i, j]);
        V = v;
    }
    public static implicit operator Matrix(int[,] matrix) => new(matrix);
    static Matrix With(long[,] matrix) => new(){ V = matrix };

    public static Matrix IdentityMatrix(int size)
    {
        var v = new long[size, size];
        for (var i = 0; i < size; i++) v[i, i] = 1;
        return With(v);
    }

    public static Matrix operator +(Matrix a, Matrix b)
    {
        var (v, va, vb, x, y) = (new long[a.X, a.Y], a.V, b.V, a.X, a.Y);
        for (var i = 0; i < x; i++) for (var j = 0; j < y; j++)
        {
            var sum = va[i, j] + vb[i, j];
            if (sum > p) sum -= p;
            v[i, j] = sum;
        }
        return With(v);
    }

    public static Matrix operator *(Matrix a, Matrix b)
    {
        var (v, va, vb, x, y, z) = (new long[a.X, b.Y], a.V, b.V, a.X, b.Y, a.Y);
        for (var i = 0; i < x; i++) for (var k = 0; k < z; k++)
        {
            var c = va[i, k];
            if (c != 0) for (var j = 0; j < y; j++) v[i, j] += vb[k, j] * c % p;
        }
        for (var i = 0; i < x; i++) for (var j = 0; j < y; j++) v[i, j] = Mod(v[i, j]);
        return With(v);
    }

    public static Matrix operator *(Matrix a, long k)
    {
        var (v, va, x, y) = (new long[a.X, a.Y], a.V, a.X, a.Y);
        for (var i = 0; i < x; i++) for (var j = 0; j < y; j++) v[i, j] = va[i, j] * k % p;
        return With(v);
    }

    public Matrix Power(long k)
    {
        var c = IdentityMatrix(X);
        var c2 = this;
        while (k > 0)
        {
            if ((k & 1) > 0) c *= c2;
            c2 *= c2;
            k >>= 1;
        }
        return c;
    }
}

static class Extensions
{
    public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}

class AtCoder
{
    const int Mod = 998244353;
    object? Solve()
    {
        var n = Int();
        var m = Int();
        var k = Int();
        var cz = k.Repeat(Int);
        var vl = new int[6, 1];
        vl[0, 0] = 1;
        var ma = new int[6, 6];
        for (var i = 0; i < 6; i++)
        {
            ma[i, 0] = 1;
            if (i + 1 < 6) ma[i, i + 1] = 1;
        }
        var matrix = new Matrix(ma);
        var vr = new int[6, 1];
        for (var i = 0; i < 6; i++) vr[i, 0] = 6 - i;
        var ans = new List<long>();
        var e = n * m - 1;
        var mv = (matrix.Power(n) * vl)[0, 0];
        foreach (var c in cz)
        {
            Int128 kns = 0;
            var ll = (matrix.Power(c) * vl)[0, 0];
            var lr = (matrix.Power(e - c) * vr)[0, 0];
            var rl = (matrix.Power(c + n) * vl)[0, 0];
            var rr = (matrix.Power(e - (c + n)) * vr)[0, 0];
            kns += ll * lr;
            kns += rl * rr;
            kns -= ll * rr * mv;
            ans.Add((long)kns % Mod);
        }
        Out(ans);
        return null;
    }

    public static void Main() => new AtCoder().Run();
    public void Run()
    {
        var res = Solve();
        if (res != null)
        {
            if (res is bool yes) res = yes ? "Yes" : "No";
            sw.WriteLine(res);
        }
        sw.Flush();
    }

    string[] input = Array.Empty<string>();
    int iter = 0;
    readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };

    string String()
    {
        while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
        return input[iter++];
    }
    T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
    int Int() => Input<int>();
    void Out(object? x, string? separator = null)
    {
        separator ??= Environment.NewLine;
        if (x is System.Collections.IEnumerable obj and not string)
        {
            var firstLine = true;
            foreach (var item in obj)
            {
                if (!firstLine) sw.Write(separator);
                firstLine = false;
                sw.Write(item);
            }
        }
        else sw.Write(x);
        sw.WriteLine();
    }
}
0