結果

問題 No.134 走れ!サブロー君
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-05-24 09:51:58
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 2,492 bytes
コンパイル時間 2,815 ms
コンパイル使用メモリ 160,356 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2023-09-04 01:14:17
合計ジャッジ時間 4,156 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


real X0, Y0;
int N;
real[] X, Y, W;

void main() {
  try {
    for (; ; ) {
      X0 = readReal();
      Y0 = readReal();
      N = readInt() + 1;
      X = new real[N];
      Y = new real[N];
      W = new real[N];
      X[0] = X0;
      Y[0] = Y0;
      W[0] = 0.0;
      foreach (u; 1 .. N) {
        X[u] = readReal();
        Y[u] = readReal();
        W[u] = readReal();
      }
      
      auto sums = new real[1 << N];
      sums[0] = 0.0;
      foreach (u; 0 .. N) {
        foreach (s; 0 .. 1 << u) {
          sums[s | 1 << u] = sums[s] + W[u];
        }
      }
      auto dp = new real[][](1 << N, N);
      foreach (s; 0 .. 1 << N) {
        dp[s][] = real.infinity;
      }
      dp[1 << 0][0] = 0.0;
      foreach (s; 0 .. 1 << N) {
        foreach (u; 0 .. N) {
          if ((s >> u) & 1) {
            foreach (v; 0 .. N) {
              if (!((s >> v) & 1)) {
                chmin(dp[s | 1 << v][v], dp[s][u] + (abs(X[u] - X[v]) + abs(Y[u] - Y[v])) * ((sums[((1 << N) - 1) ^ s] + 100.0) / 120.0));
              }
            }
          }
        }
      }
      real ans = real.infinity;
      foreach (u; 1 .. N) {
        chmin(ans, dp[(1 << N) - 1][u] + (abs(X[u] - X[0]) + abs(Y[u] - Y[0])) * (100.0 / 120.0));
      }
      ans += sums[(1 << N) - 1];
      writefln("%.10f", ans);
    }
  } catch (EOFException e) {
  }
}
0