結果

問題 No.1599 Hikyaku
ユーザー olpheolphe
提出日時 2021-07-09 22:58:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,985 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 124,896 KB
実行使用メモリ 484,588 KB
最終ジャッジ日時 2023-09-14 10:33:31
合計ジャッジ時間 30,121 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 OLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

struct Node {
	int y, x, v, ok;
	long double cost;
	Node(int y, int x, int v, int ok,long double cost) :y(y), x(x), v(v), ok(ok),cost(cost) {

	}
	bool operator<(const Node& n)const {
		return cost > n.cost;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	H = 600, W = 600;
	int gy, gx;
	cin >> gy >> gx;
	gy--, gx--;
	cin >> N;
	vector<vector<vector<vector<long double>>>>dis(H, vector<vector<vector<long double>>>(W, vector<vector<long double>>(8, vector<long double>(2, MOD))));
	priority_queue<Node>PQ;
	int exist[8] = {};
	for (int i = 0; i < N; i++) {
		int y, x, v;
		cin >> y >> x >> v;
		exist[v] = 1;
		y--, x--;
		if (i) {
			dis[y][x][v][0] = 0;
			PQ.push(Node(y, x, v, 0, 0));
		}
		else {
			dis[y][x][v][1] = 0;
			PQ.push(Node(y, x, v, 1, 0));
		}
	}
	int dir[] = { 1,0,-1,0,1 };
	while (!PQ.empty()) {
		auto box = PQ.top();
		if (box.cost < 1300) {
			cout << box.y << " " << box.x << " " << box.v << " " << box.ok << " " << box.cost << endl;
		}
		PQ.pop();
		if (box.ok) {
			for (int i = 1; i < 8; i++) {
				if (!exist[i])continue;
				if (dis[box.y][box.x][i][1] > dis[box.y][box.x][i][0] && dis[box.y][box.x][i][0] > box.cost) {
					dis[box.y][box.x][i][1] = dis[box.y][box.x][i][0];
					PQ.push(Node(box.y, box.x, i, 1, dis[box.y][box.x][i][0]));
				}
			}
		}
		else {
			for (int i = 1; i < 8; i++) {
				if (!exist[i])continue;
				if (dis[box.y][box.x][i][1] > box.cost) {
					long double d = box.cost + (dis[box.y][box.x][i][1] - box.cost) * i / (i + box.v) * 2;
					if (dis[box.y][box.x][box.v][1] > d) {
						PQ.push(Node(box.y, box.x, box.v, 1, d));
					}
				}
				if (dis[box.y][box.x][i][1] <= box.cost) {
					if (dis[box.y][box.x][box.v][1] > box.cost) {
						PQ.push(Node(box.y, box.x, box.v, 1, box.cost));
					}
				}
			}
		}
		for (int d = 0; d < 4; d++) {
			int ny = box.y + dir[d];
			int nx = box.x + dir[d + 1];
			if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
			if (dis[ny][nx][box.v][box.ok] > box.cost + ((long double)1000) / box.v) {
				dis[ny][nx][box.v][box.ok] = box.cost + ((long double)1000) / box.v;
				PQ.push(Node(ny, nx, box.v, box.ok, box.cost + ((long double)1000) / box.v));
			}
		}
	}
	long double ans = MOD;
	for (int i = 1; i <= 7; i++) {
		ans = min(ans, dis[gy][gx][i][1]);
	}
	cout << fixed << setprecision(20) << ans << endl;
}
0