結果

問題 No.134 走れ!サブロー君
ユーザー nobuta05nobuta05
提出日時 2022-04-02 15:28:42
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 2,418 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 156,220 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 16:36:13
合計ジャッジ時間 3,282 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio, std.string, std.conv;
import std.algorithm, std.math;
import std.range;
import std.container.rbtree, std.container.dlist;
import std.container.binaryheap, std.container.array;
import std.typecons;

alias mstring = char[];
const long INF = 1L << 60L;
const long mod = 1_000_000_000 + 7;

void chmin (T)(ref T x, T y) {
  x = min(x, y);
}

void chmax (T)(ref T x, T y) {
  x = max(x, y);
}

// 単一の数値を取得
// readln.chomp.to!int;
//  or
// int a;
// readf("%s\n", a);

// 複数の数値を取得(可変数個の場合推奨)
// readln.chomp.split.map!(to!long).array

// 複数の数値を取得(固定数個の場合、推奨)
// int a, b;
// readf("%s %s\n", &a, &b);

// インデントを一個ずらして複数の数値を取得(累積和とかで1-indexedの方が良い時がある)
// long[] vs = readln.chomp.split.map!(to!long).array;
// vs = [0L] ~ vs;

// 小数点は以下で指定
// double ret = 10.0;
// writefln("%.12f", ret);

// 配列の最後の要素は arr[$-1] でアクセスできる

void main () {
  int x0, y0;
  readf("%s %s\n", &x0, &y0);
  int N = readln.chomp.to!int;
  auto info = new Tuple!(int, int, double)[](N + 1);
  info[0][0] = x0;
  info[0][1] = y0;
  info[0][2] = 0L;
  foreach (i; 1 .. N + 1)
    readf ("%s %s %s\n", &(info[i][0]), &(info[i][1]), &(info[i][2]));

  auto dist = new long[][](N + 1, N + 1);
  foreach (u; 0 .. N + 1)
    foreach (v; 0 .. N + 1)
      dist[u][v] = abs(info[v][0] - info[u][0]) + abs(info[v][1] - info[u][1]);
  auto ws = new double[](1 << N);
  foreach (s; 0 .. (1 << N)) {
    double tot = 0L;
    foreach (u; 1 .. N + 1) {
      if (s & (1 << (u - 1)))
        continue;
      tot += info[u][2];
    }
    ws[s] = tot;
  }

  auto dp = new double[][](1 << N, N + 1);
  foreach (s; 0 .. (1 << N))
    foreach (u; 0 .. N + 1)
      dp[s][u] = cast(double)(INF);
  dp[0][0] = 0.0;

  foreach (s; 0 .. (1 << N)) {
    foreach (u; 0 .. N + 1) {
      if (dp[s][u] == cast(double)(INF))
        continue;

      foreach (v; 1 .. N + 1) {
        if (s & (1 << (v - 1)))
          continue;
        auto cst = dist[u][v] * (ws[s] + 100.0) / 120.0;

        chmin(dp[s | (1 << (v - 1))][v], dp[s][u] + cst);
      }
    }
  }

  double ret = cast(double)(INF);
  foreach (u; 1 .. N + 1) {
    auto cst = dist[u][0] * 100.0 / 120.0;
    chmin(ret, dp[(1 << N) - 1][u] + cst);
  }

  writefln("%.12f", ret + ws[0]);
}
0