結果

問題 No.1 道のショートカット
ユーザー te-shte-sh
提出日時 2017-01-12 18:57:41
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,088 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 92,528 KB
実行使用メモリ 5,120 KB
最終ジャッジ日時 2023-09-03 00:35:21
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,380 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 1 ms
4,380 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void main()
{
  auto n = readln.chomp.to!size_t;
  auto c = readln.chomp.to!int;
  auto v = readln.chomp.to!size_t;
  auto si = readln.split.to!(size_t[]).map!"a - 1".array;
  auto ti = readln.split.to!(size_t[]).map!"a - 1".array;
  auto yi = readln.split.to!(int[]);
  auto mi = readln.split.to!(int[]);

  auto yij = new int[][](n, n);
  auto mij = new int[][](n, n);
  foreach (i; v.iota) {
    yij[si[i]][ti[i]] = yi[i];
    mij[si[i]][ti[i]] = mi[i];
  }

  auto dp = new int[int][](n);
  dp[0][0] = 0;

  foreach (i; 0..n-1) {
    foreach (j; i+1..n) {
      auto y = yij[i][j], m = mij[i][j];
      if (y > 0 || m > 0) {
        foreach (k; dp[i].byKeyValue) {
          auto ny = k.key + y;
          auto nm = k.value + m;
          if (ny <= c) {
            if (ny in dp[j])
              dp[j][ny] = min(dp[j][ny], nm);
            else
              dp[j][ny] = nm;
          }
        }
      }
    }
  }

  auto ri = dp[n - 1].values;
  if (ri.empty)
    writeln(-1);
  else
    writeln(ri.reduce!min);
}
0