結果

問題 No.134 走れ!サブロー君
ユーザー fiordfiord
提出日時 2015-08-18 23:12:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 976 bytes
コンパイル時間 1,246 ms
コンパイル使用メモリ 148,860 KB
実行使用メモリ 4,636 KB
最終ジャッジ日時 2023-09-25 12:56:26
合計ジャッジ時間 1,970 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
double dp[1<<14][14];
double weight[1<<14];
int main(){
	int sx,sy;	cin>>sx>>sy;
	int n;	cin>>n;
	vector<int> x(n),y(n);
	vector<double> w(n);
	for(int i=0;i<n;i++)	cin>>x[i]>>y[i]>>w[i];
	int sw=0;
	for(int i=0;i<n;i++)	sw+=w[i];
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if((i>>j)%2)	weight[i]+=w[j];
		}
		weight[i]=sw-weight[i];
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++)	dp[i][j]=(1<<30);
	}
	for(int i=0;i<n;i++){
		dp[(1<<i)][i]=(double)(abs(sx-x[i])+abs(sy-y[i]))*(sw+100)/120+w[i];
	}
	for(int i=1;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if((i>>j)%2==0)	continue;
			for(int k=0;k<n;k++){
				int next=(i|(1<<k));
				dp[next][k]=min(dp[next][k],dp[i][j]+(double)(abs(x[j]-x[k])+abs(y[j]-y[k]))*(weight[i]+100)/120+w[k]);
			}
		}
	}
	double ans=(1<<30);
	for(int i=0;i<n;i++){
		ans=min(ans,dp[(1<<n)-1][i]+(double)(abs(x[i]-sx)+abs(y[i]-sy))*100/120);
	}
	printf("%.15lf\n",ans);
	return 0;
}
0