結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-24 19:52:19
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,384 ms / 2,000 ms
コード長 2,004 bytes
コンパイル時間 7,288 ms
コンパイル使用メモリ 156,868 KB
実行使用メモリ 182,176 KB
最終ジャッジ日時 2023-12-24 19:52:43
合計ジャッジ時間 24,363 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
32,676 KB
testcase_01 AC 84 ms
32,548 KB
testcase_02 AC 81 ms
32,676 KB
testcase_03 AC 82 ms
32,676 KB
testcase_04 AC 111 ms
33,444 KB
testcase_05 AC 82 ms
32,676 KB
testcase_06 AC 82 ms
32,676 KB
testcase_07 AC 82 ms
32,676 KB
testcase_08 AC 318 ms
34,340 KB
testcase_09 AC 288 ms
34,340 KB
testcase_10 AC 289 ms
34,340 KB
testcase_11 AC 240 ms
34,212 KB
testcase_12 AC 331 ms
34,724 KB
testcase_13 AC 290 ms
34,596 KB
testcase_14 AC 1,215 ms
40,484 KB
testcase_15 AC 1,239 ms
40,484 KB
testcase_16 AC 1,252 ms
40,484 KB
testcase_17 AC 1,384 ms
40,612 KB
testcase_18 AC 1,302 ms
40,868 KB
testcase_19 AC 1,244 ms
40,484 KB
testcase_20 AC 894 ms
38,820 KB
testcase_21 AC 1,116 ms
39,460 KB
testcase_22 AC 239 ms
35,108 KB
testcase_23 AC 1,187 ms
40,356 KB
testcase_24 AC 205 ms
34,596 KB
testcase_25 AC 380 ms
36,004 KB
testcase_26 AC 178 ms
34,340 KB
testcase_27 AC 84 ms
33,060 KB
testcase_28 AC 89 ms
33,188 KB
testcase_29 AC 85 ms
32,932 KB
testcase_30 AC 237 ms
35,108 KB
testcase_31 AC 229 ms
35,108 KB
testcase_32 AC 225 ms
34,980 KB
testcase_33 AC 223 ms
182,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (107 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();
    static long[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m, t) = (c[0], c[1], c[2]);
        var map = NArr(m);
        var a = new long[1][];
        a[0] = new long[n];
        a[0][0] = 1;
        var x = new long[n][];
        for (var i = 0; i < x.Length; ++i) x[i] = new long[n];
        foreach (var edge in map)
        {
            x[edge[0]][edge[1]] = 1;
            x[edge[1]][edge[0]] = 1;
        }
        var b = Matrix.Mul(a, Matrix.Pow(x, t));
        WriteLine(b[0][0]);
    }
    class Matrix
    {
        static int mod = 998_244_353;
        // 行列の累乗
        public static long[][] Pow(long[][] m, long k)
        {
            var multi = m;
            var r = new long[m.Length][];
            for (var i = 0; i < m.Length; ++i)
            {
                r[i] = new long[m.Length];
                r[i][i] = 1;
            }
            while (k > 0)
            {
                if ((k & 1) == 1) r = Mul(r, multi);
                multi = Mul(multi, multi);
                k >>= 1;
            }
            return r;
        }
        // 行列の積
        public static long[][] Mul(long[][] x, long[][] y)
        {
            var r = new long[x.Length][];
            for (var i = 0; i < x.Length; ++i) r[i] = new long[y[0].Length];
            for (var i = 0; i < x.Length; ++i) for (var k = 0; k < x[0].Length; ++k)
            {
                for (var j = 0; j < y[0].Length; ++j) r[i][j] = (r[i][j] + x[i][k] * y[k][j]) % mod;
            }
            return r;
        }
    }
}
0