結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,372 KB
testcase_14 AC 1 ms
4,372 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;
    }
  }

  writeln(memo[$-1][$-1] / 120 + sumW);
}
0