結果

問題 No.134 走れ!サブロー君
ユーザー te-shte-sh
提出日時 2016-09-07 13:54:24
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 151 ms / 5,000 ms
コード長 1,426 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 175,664 KB
実行使用メモリ 9,348 KB
最終ジャッジ日時 2023-09-02 21:58:57
合計ジャッジ時間 3,447 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

struct point {
  int x, y;

  point opBinary(string op)(point rhs) {
    static if (op == "+") return point(x + rhs.x, y + rhs.y);
    else static if (op == "-") return point(x - rhs.x, y - rhs.y);
  }

  int absMan() { return x.abs + y.abs; }
}

alias Tuple!(point, "p", real, "w") posWeight;

void main()
{
  auto rd = readln.split.map!(to!int);
  auto x0 = point(rd[0], rd[1]);
  auto n = readln.chomp.to!size_t;
  auto pi = iota(n)
    .map!(_ => readln.split)
    .map!(rd => posWeight(point(rd[0].to!int, rd[1].to!int), rd[2].to!real)).array;

  pi ~= posWeight(x0, 0);
  n += 1;

  auto sumW = pi.map!("a.w").sum;

  real restW(size_t visited) {
    return sumW - visited.bitsSet.map!(a => pi[a].w).sum;
  }

  auto memo = new real[][](1 << n, n);

  foreach (size_t i; 1..(1 << n)) {
    foreach (j; i.bitsSet) {
      auto k = i;
      btr(&k, j);
      auto minT = real.max;
      if (k == 0) {
        minT = (pi[j].p - x0).absMan * (100 + sumW);
      } else {
        foreach (l; k.bitsSet) {
          auto t = memo[k][l] + (pi[l].p - pi[j].p).absMan * (100 + restW(k));
          minT = min(minT, t);
        }
      }
      memo[i][j] = minT;
    }
  }

  writefln("%.7f", memo[$-1][$-1] / 120 + sumW);
}
0