結果

問題 No.1638 Robot Maze
ユーザー pengin_2000pengin_2000
提出日時 2021-08-06 22:09:50
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,719 bytes
コンパイル時間 1,094 ms
コンパイル使用メモリ 32,200 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 03:32:22
合計ジャッジ時間 2,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
long long int dist[102][102];
int h[200005], hl;
int comp_h(int a, int b)
{

	if (dist[h[a] / 101][h[a] % 101] > dist[h[b] / 101][h[b] % 101])
		return 1;
	else
		return -1;
}
void swap_h(int a, int b)
{
	int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(int ne)
{
	h[hl] = ne;
	int p = hl;
	hl++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	hl--;
	swap_h(0, hl);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < hl)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < hl)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[hl];
}
int main()
{
	int h, w;
	scanf("%d %d", &h, &w);
	long long int u, d, r, l, k, p;
	scanf("%lld %lld %lld %lld %lld %lld", &u, &d, &r, &l, &k, &p);
	int xs, ys, xt, yt;
	scanf("%d %d %d %d", &xs, &ys, &xt, &yt);
	xs--;
	xt--;
	ys--;
	yt--;
	char c[102][102];
	int i, j;
	for (i = 0; i < h; i++)
		scanf("%s", c[i]);
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			dist[i][j] = k + 10;
	hl = 0;
	dist[xs][ys] = 0;
	push(101 * xs + ys);
	while (hl > 0)
	{
		i = pop();
		j = i % 101;
		i /= 101;
		if (i > 0)
		{
			if (c[i - 1][j] == '.' && dist[i - 1][j] > dist[i][j] + u)
			{
				dist[i - 1][j] = dist[i][j] + u;
				push(101 * (i - 1) + j);
			}
			else if (c[i - 1][j] == '@' && dist[i - 1][j] > dist[i][j] + u + p)
			{
				dist[i - 1][j] = dist[i][j] + u + p;
				push(101 * (i - 1) + j);
			}
		}
		if (i < h - 1)
		{
			if (c[i + 1][j] == '.' && dist[i + 1][j] > dist[i][j] + d)
			{
				dist[i + 1][j] = dist[i][j] + d;
				push(101 * (i + 1) + j);
			}
			else if (c[i + 1][j] == '@' && dist[i + 1][j] > dist[i][j] + d + p)
			{
				dist[i + 1][j] = dist[i][j] + d + p;
				push(101 * (i + 1) + j);
			}
		}
		if (j > 0)
		{
			if (c[i][j - 1] == '.' && dist[i][j - 1] > dist[i][j] + l)
			{
				dist[i][j - 1] = dist[i][j] + l;
				push(101 * i + j - 1);
			}
			else if (c[i][j - 1] == '@' && dist[i][j - 1] > dist[i][j] + l + p)
			{
				dist[i][j - 1] = dist[i][j] + l + p;
				push(101 * i + j - 1);
			}
		}
		if (j < w - 1)
		{
			if (c[i][j + 1] == '.' && dist[i][j + 1] > dist[i][j] + r)
			{
				dist[i][j + 1] = dist[i][j] + r;
				push(101 * i + j + 1);
			}
			else if (c[i][j + 1] == '@' && dist[i][j + 1] > dist[i][j] + r + p)
			{
				dist[i][j + 1] = dist[i][j] + r + p;
				push(101 * i + j + 1);
			}
		}
	}
	if (dist[xt][yt] <= k)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}
0