結果

問題 No.30 たこやき工場
ユーザー te-shte-sh
提出日時 2017-01-17 11:29:19
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 768 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 89,412 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 00:40:28
合計ジャッジ時間 1,935 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto m = readln.chomp.to!size_t;

  auto qij = new int[][](n, n);
  foreach (_; m.iota) {
    auto rd = readln.split;
    auto p = rd[0].to!size_t - 1, q = rd[1].to!int, r = rd[2].to!size_t - 1;
    qij[r][p] = q;
  }

  auto memo = new int[][](n);

  auto calc(size_t i)
  {
    if (!memo[i].empty) {
      return memo[i];
    } else if (qij[i].all!"a == 0") {
      auto qi = new int[](n);
      qi[i] = 1;
      return memo[i] = qi;
    } else {
      auto qi = new int[](n);
      foreach (j, q; qij[i]) {
        if (q > 0)
          qi[] += calc(j)[] * q;
      }
      return memo[i] = qi;
    }
  }

  calc(n - 1).take(n - 1).each!writeln;
}
0