結果

問題 No.134 走れ!サブロー君
ユーザー 0w10w1
提出日時 2017-01-02 16:09:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 2,090 bytes
コンパイル時間 1,922 ms
コンパイル使用メモリ 171,636 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-22 07:49:45
合計ジャッジ時間 2,686 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int X0, Y0;
int N;
vi X, Y;
vd W;

void init(){
  cin >> X0 >> Y0;
  cin >> N;
  X = Y = vi( N );
  W = vd( N );
  for( int i = 0; i < N; ++i ){
    cin >> X[ i ] >> Y[ i ] >> W[ i ];
  }
}

const int MAXN = 13;

double wtot;
double dp[ 1 << MAXN ][ MAXN ];

double man_dis( double x, double y, double a, double b ){
  double dx = x - a;
  double dy = y - b;
  return fabs( dx ) + fabs( dy );
}

void preprocess(){
  for( int i = 0; i < N; ++i ){
    wtot += W[ i ];
  }
  for( int i = 0; i < 1 << N; ++i ){
    for( int j = 0; j < N; ++j ){
      dp[ i ][ j ] = INF;
    }
  }
  for( int i = 0; i < N; ++i ){
    dp[ 1 << i ][ i ] = man_dis( X0, Y0, X[ i ], Y[ i ] ) * ( wtot + 100 ) / 120 + W[ i ];
  }
  for( int s = 0; s < 1 << N; ++s ){
    double load_sum = 0;
    for( int i = 0; i < N; ++i ){
      if( ~s & 1 << i ){
        load_sum += W[ i ];
      }
    }
    for( int i = 0; i < N; ++i ){
      if( s & 1 << i ){ // prev last
        for( int j = 0; j < N; ++j ){
          if( ~s & 1 << j ){ // new last
            upmin( dp[ s | 1 << j ][ j ], dp[ s ][ i ] + man_dis( X[ i ], Y[ i ], X[ j ], Y[ j ] ) * ( load_sum + 100 ) / 120 + W[ j ] );
          }
        }
      } 
    }
  }
}

void solve(){
  double ans = INF;
  for( int i = 0; i < N; ++i ){
    upmin( ans, dp[ ( 1 << N ) - 1 ][ i ] + man_dis( X0, Y0, X[ i ], Y[ i ] ) * 100.0 / 120 );
  }
  cout << fixed << setprecision( 9 ) << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0