結果

問題 No.134 走れ!サブロー君
ユーザー tumuztumuz
提出日時 2023-10-14 08:59:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,868 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 204,396 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-10-14 08:59:36
合計ジャッジ時間 3,180 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep1(i,n) for(int i=1; i<=(n); i++)
#define sz(x) int(x.size())
#define all(x) (x).begin(),(x).end()
#define Q2 1000000007
#define Q 998244353
#define lINF LONG_LONG_MAX  //ll
#define iINF 1e9 //int
#define yes "Yes"
#define no "No"
#define kotae cout<<ans<<endl;
#define dame { puts("0"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
using ll=long long;
using ull=unsigned long long;
using P=pair<int,int>;
using pqg=priority_queue<int,vector<int>,greater<int>>;
using vi=vector<int>;
using vi2=vector<vector<int>>;
using vi3=vector<vector<vector<int>>>;
using vl=vector<ll>;
using vl2=vector<vector<ll>>;
using vl3=vector<vector<vector<ll>>>;
using vs=vector<string>;
using vp=vector<P>;
using vp2=vector<vector<P>>;
void chmax(int &x, int y){ x=max(x,y); return; }
void chmin(double &x, double y){ x=min(x,y); return; }
void chmaxl(ll &x, ll y){ x=max(x,y); return; }
void chminl(ll &x, ll y){ x=min(x,y); return; }

struct A{
  int x,y;
  double w;
};

int main() {  

  int x,y;
  cin >> x >> y;
  int n;
  cin >> n;
  vector<A>a(n);
  rep(i,n) cin >> a[i].x >> a[i].y >> a[i].w;
  int s=1<<n;
  vector<vector<double>> dp(s,vector<double>(n,iINF));
  double tot=0;
  double l=100,r=120;
  rep(i,n) tot+=a[i].w;
  rep(i,n) dp[1<<i][i]=(abs(a[i].x-x)+abs(a[i].y-y))*(tot+100)/120+a[i].w;

  rep(i,s){
    rep(j,n){ //goto j
      if((i>>j)&1) continue;
      double nw=tot;
      rep(k,n) if((i>>k)&1) nw-=a[k].w; 
      double t=(nw+100)/120;

      rep(k,n){  //from k
        if(!(i>>k)&1) continue;
        double nt=(abs(a[j].x-a[k].x)+abs(a[j].y-a[k].y))*t;
        chmin (dp[i|(1<<j)][j], dp[i][k]+nt+a[j].w);
      }
    }
  }
  double ans=iINF;
  rep(i,n) chmin(ans,dp[s-1][i]+(abs(a[i].x-x)+abs(a[i].y-y))*l/r);
  printf("%.10f\n",ans);
  return 0;
}
0