結果

問題 No.134 走れ!サブロー君
ユーザー kakeyamaykakeyamay
提出日時 2019-07-03 12:26:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,086 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 205,468 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-10-12 20:10:12
合計ジャッジ時間 3,278 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
	
	int X0,Y0;
	std::cin >> X0 >> Y0;
	int N;
	std::cin >> N;
	std::vector<int> X(N);
	std::vector<int> Y(N);
	std::vector<double> W(N);
	for(int i=0;i<N;++i)
		std::cin >> X[i] >> Y[i] >> W[i];
	int n=1<<N;
	std::vector<std::vector<double>> dp(n,std::vector<double>(N,DBL_MAX));
	auto calc = [&](int x, int y){
		return std::abs(x)+std::abs(y);
	};
	double sumW = std::accumulate(begin(W),end(W),0.0);
	for(int i=0;i<N;++i)
		dp[0][i] = (sumW+100)/120*calc(X0-X[i],Y0-Y[i]);
	for(int x=0;x<n;++x){
		double SW = 0;
		//積んでいる荷物の重さ
		for(int i=0;i<N;++i)
			if(!(x&(1<<i)))SW += W[i];
		for(int i=0;i<N;++i){
			if(x&(1<<i))continue;
			for(int j=0;j<N;++j){
				if(dp[x][j]==DBL_MAX)continue;
				double T = (SW+100)/120*calc(X[j]-X[i],Y[j]-Y[i]);
				int v=x|(1<<i);
				dp[v][i]=std::min(dp[v][i],dp[x][j]+T);
			}
		}
	}
	double ans = DBL_MAX;
	for(int i=0;i<N;++i){
		ans = std::min(ans,dp[n-1][i]+100/120.0*calc(X0-X[i],Y0-Y[i]));
	}
	ans += sumW;
	std::cout << std::fixed << std::setprecision(8) << ans << std::endl;
}
0