結果

問題 No.134 走れ!サブロー君
ユーザー ありあり
提出日時 2023-02-08 13:12:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,670 bytes
コンパイル時間 1,418 ms
コンパイル使用メモリ 82,804 KB
実行使用メモリ 12,116 KB
最終ジャッジ日時 2023-09-20 05:42:19
合計ジャッジ時間 2,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,756 KB
testcase_01 AC 5 ms
11,876 KB
testcase_02 AC 5 ms
11,720 KB
testcase_03 AC 5 ms
11,920 KB
testcase_04 AC 5 ms
11,932 KB
testcase_05 AC 5 ms
11,768 KB
testcase_06 AC 6 ms
11,796 KB
testcase_07 AC 8 ms
12,040 KB
testcase_08 AC 12 ms
12,116 KB
testcase_09 AC 12 ms
12,088 KB
testcase_10 AC 5 ms
11,776 KB
testcase_11 AC 5 ms
11,872 KB
testcase_12 AC 5 ms
11,844 KB
testcase_13 AC 5 ms
11,852 KB
testcase_14 AC 5 ms
11,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cassert>
#include <cmath>
#include <bitset>
using namespace std;

int n;
double x[16], y[16], w[16];
double d[16][16];
double sw[1<<16], t[1<<16], dp[1<<16][16];
const double inf = 1e18;

void chmin(double &a, double b) {
  a = min(a, b);
}

int main() {
  cin >> x[0] >> y[0];
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> w[i];

  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) {
      d[i][j] = abs(x[i]-x[j]) + abs(y[i]-y[j]);
      //printf("d[%d][%d] = %lf\n", i, j, d[i][j]);
    }
  

  for (int i = 0; i <= n; i++) sw[0] += w[i];
  for (int s = 0; s < (1<<(n+1)); s++)
    for (int i = 0; i <= n; i++)
      if (~s&(1<<i)) 
        sw[s|(1<<i)] = sw[s] - w[i];

  for (int s = 0; s < (1<<(n+1)); s++)
    t[s] = (sw[s] + 100.0) / 120.0;

  //for (int s = 0; s < (1<<(n+1)); s++) cout << "sw[" << bitset<4>(s) << "] = " << sw[s] << endl;
  //for (int s = 0; s < (1<<(n+1)); s++) cout << "t[" << bitset<4>(s) << "] = " << t[s] << endl;

  for (int s = 0; s < (1<<16); s++)
    for (int v = 0; v < 16; v++)
      dp[s][v] = inf;

  dp[0][0] = 0;
  for (int s = 0; s < (1<<(n+1)); s++)
    for (int v = 0; v <= n; v++) {
      if (dp[s][v] == inf) continue;
      for (int u = 0; u <= n; u++)
        if (~s&(1<<u))
          chmin(dp[s|(1<<u)][u], dp[s][v] + d[v][u]*t[s] + w[u]);
    }

  //for (int s = 0; s < (1<<(n+1)); s++) for (int v = 0; v <= n; v++) cout << "dp[" << bitset<4>(s) << "][" << v << "] = " << dp[s][v] << endl;
  printf("%.10lf\n", dp[(1<<(n+1))-1][0]);
}
0