結果

問題 No.134 走れ!サブロー君
ユーザー imgry22imgry22
提出日時 2015-01-23 22:32:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 1,493 bytes
コンパイル時間 1,344 ms
コンパイル使用メモリ 158,440 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-22 18:01:24
合計ジャッジ時間 2,093 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000.0
#define MOD 1000000007
#define EPS 1E-12

const int MAX_N = 14;
int s, t;
int x[MAX_N], y[MAX_N];
double w[MAX_N];
double dp[1<<MAX_N][MAX_N];
int n;

double cost(int S)
{
  double res = 0.0;
  rep(i, n) if(!(S & 1 << i)) res += w[i];
  return (res + 100) / 120.0;
}
inline double dist(int i, int j, int S){ return (abs(x[i]-x[j])+abs(y[i]-y[j]))*cost(S); }

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


  rep(S, 1<<n) rep(v, n) dp[S][v] = INF;
  dp[0][0] = 0.0;

  rep(S, 1<<n) rep(v, n) if(dp[S][v] < INF) rep(u, n) if(!(S & 1 << u)) minup(dp[S | 1 << u][u], dp[S][v] + dist(v, u, S) + w[u]);

  printf("%.10f\n", dp[(1<<n)-1][0]);

  return 0;
}
0