結果

問題 No.134 走れ!サブロー君
ユーザー orange orangeorange orange
提出日時 2023-10-16 20:16:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,482 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 101,420 KB
実行使用メモリ 6,288 KB
最終ジャッジ日時 2023-10-16 20:16:27
合計ジャッジ時間 1,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<climits>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<assert.h>
#include<numeric>
#include<bitset>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
using namespace std;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 62;
const double PI = 2 * acos(0.0);
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }

int N;
double X[20], Y[20], W[20];
double dp[20000][20];
int main() {
	cin >> X[0] >> Y[0];
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> X[i] >> Y[i] >> W[i];
	for (int i = 0; i < 1 << (N + 1); i++) for (int j = 0; j < N + 1; j++) dp[i][j] = infl;
	dp[0][0] = 0;

	for (int msk = 0; msk < 1 << (N + 1); msk++) {
		double w = 0;
		for (int i = 0; i < N + 1; i++) if (!(msk & 1 << i)) w += W[i];
		double T = (w + 100) / 120;

		for (int i = 0; i < N + 1; i++) {
			for (int j = 0; j < N + 1; j++) {
				if (msk & 1 << j) continue;
				double dis = 1.0 * (abs(X[j] - X[i]) + abs(Y[j] - Y[i]));
				chmin(dp[msk + (1 << j)][j], dp[msk][i] + dis * T + W[i]);
			}
		}
	}
	
	printf("%.10f\n", dp[(1 << (N + 1)) - 1][0]);
}
0