結果

問題 No.572 妖精の演奏
ユーザー nebukuro09nebukuro09
提出日時 2018-06-18 10:30:03
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 905 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 108,952 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 20:26:36
合計ジャッジ時間 1,825 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,384 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!long - 1;
    auto M = readln.chomp.to!int;
    auto A = M.iota.map!(_ => readln.split.map!(to!long).array).array;
    auto B = new long[][](M, M);

    long[][] mul(const long[][] a, const long[][] b) {
        auto ret = new long[][](M, M);
        foreach (i; 0..M)
            foreach (j; 0..M)
                ret[i][j] = a[i][j];
        foreach (i; 0..M)
            foreach (j; 0..M)
                foreach (k; 0..M)
                    ret[j][k] = max(ret[j][k], a[j][i] + b[i][k]);
        return ret;
    }

    while (N) {
        if (N & 1) 
            B = mul(B, A);
        A = mul(A, A);
        N >>= 1;
    }

    B.map!(b => b.reduce!max).reduce!max.writeln;
}
0