結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー kokatsukokatsu
提出日時 2021-11-20 00:25:22
言語 D
(dmd 2.106.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,112 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 200,360 KB
実行使用メモリ 6,524 KB
最終ジャッジ日時 2023-09-04 15:02:56
合計ジャッジ時間 24,033 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 46 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 349 ms
4,384 KB
testcase_09 AC 349 ms
4,396 KB
testcase_10 AC 349 ms
4,380 KB
testcase_11 AC 265 ms
4,384 KB
testcase_12 AC 375 ms
4,380 KB
testcase_13 AC 353 ms
4,384 KB
testcase_14 AC 1,889 ms
4,380 KB
testcase_15 AC 1,926 ms
4,384 KB
testcase_16 AC 1,949 ms
4,380 KB
testcase_17 AC 1,958 ms
4,380 KB
testcase_18 TLE -
testcase_19 AC 1,935 ms
4,380 KB
testcase_20 AC 1,336 ms
4,384 KB
testcase_21 AC 1,562 ms
4,384 KB
testcase_22 AC 267 ms
4,380 KB
testcase_23 AC 1,841 ms
4,384 KB
testcase_24 AC 208 ms
4,380 KB
testcase_25 AC 509 ms
4,380 KB
testcase_26 AC 162 ms
4,404 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 10 ms
4,380 KB
testcase_29 AC 4 ms
4,384 KB
testcase_30 AC 263 ms
4,380 KB
testcase_31 AC 246 ms
4,384 KB
testcase_32 AC 239 ms
4,384 KB
testcase_33 AC 236 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    long N, M, T;
    readf("%d %d %d\n", N, M, T);

    auto path = new long[][](N, N);
    foreach (i; 0 .. M) {
        long s, t;
        readf("%d %d\n", s, t);

        path[s][t] = 1;
        path[t][s] = 1;
    }

    enum long MOD = 998244353;

    auto mat = matPowMod(path, T, MOD);

    long res = mat[0][0];
    res.writeln;
}

long[][] matMulMod(long[][] a, long[][] b, long m) {
    long l = a[0].length.to!long;

    assert(l == b.length);

    auto res = new long[][](a.length, b[0].length);
    foreach (i, r; res) {
        foreach (k; 0 .. l) {
            foreach (j, ref e; r) {
                e = (e + a[i][k] * b[k][j] % m) % m;
            }
        }
    }

    return res;
}

long[][] matPowMod(long[][] mat, long p, long m) {
    long l = mat[0].length.to!long;

    assert(l == mat.length);

    auto res = new long[][](l, l);
    foreach (i; 0 .. l) {
        res[i][i] = 1;
    }

    while (p > 0) {
        if (p & 1) {
            res = matMulMod(res, mat, m);
        }
        mat = matMulMod(mat, mat, m);
        p >>= 1;
    }

    return res;
}
0