結果

問題 No.134 走れ!サブロー君
ユーザー cielciel
提出日時 2015-10-24 14:12:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,521 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 59,136 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-22 18:03:56
合計ジャッジ時間 1,008 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 7 ms
5,632 KB
testcase_08 AC 12 ms
8,192 KB
testcase_09 AC 13 ms
8,192 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 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
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         scanf("%lf%lf%d",&X,&Y,&N);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:51:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |                         scanf("%lf%lf%lf",&a[i].first,&a[i].second,&cost[i]);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 99999999
using namespace std;

typedef double Weight;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

const int M = 20;
Weight best[1<<M][M];
Weight total[1<<M][M];
Weight shortestHamiltonPath(const Matrix &dist, const Array &cost) {
	int n=cost.size();
	int N = 1 << n;
	REP(S,N) REP(i,n) best[S][i] = total[S][i]=INF;
	best[0][0] = 0;
	total[0][0] = 0;
	REP(i,n) total[0][0] += cost[i];
	REP(S,N) REP(j,n) if (!(S&(1<<j))) REP(i,n) {
		Weight time = dist[i][j]*(total[S][i]+100)/120 + cost[j];
		if (best[S|(1<<j)][j] >= best[S][i] + time) {
			best[S|(1<<j)][j] = best[S][i] + time;
			total[S|(1<<j)][j] = total[S][i] - cost[j];
		}
	}
	//int t = max_element(best[N-1], best[N-1]+n) - best[N-1];
	//path.clear(); buildPath(N-1, t, path);
	return best[N-1][0];
}

int main(){
	double X,Y;
	int N;
	scanf("%lf%lf%d",&X,&Y,&N);
	Array cost(N+1);
	Matrix dist(N+1);dist[0].resize(N+1);
	{
		vector<pair<double,double> >a(N+1);
		a[0].first=X,a[0].second=Y;
		for(int i=1;i<=N;i++){
			dist[i].resize(N+1);
			scanf("%lf%lf%lf",&a[i].first,&a[i].second,&cost[i]);
		}
		for(int i=0;i<=N;i++)for(int j=0;j<=N;j++)dist[i][j]=fabs(a[i].first-a[j].first)+fabs(a[i].second-a[j].second);
	}
	printf("%f\n",shortestHamiltonPath(dist,cost));
}
0