提出 #64976864


ソースコード 拡げる

#include <stdio.h>
#include <string.h>

int H, W;
char S[1024][1024];
int A, B, C, D;

const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int mincost[1024][1024][5];

struct q_s {
	int y, x;
	int mg;
} q[1024 * 1024 * 5 * 2];

int main(void) {
	int i;
	int qs = 1024 * 1024 * 5, qe = 1024 * 1024 * 5;
	int ans;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 1; i <= H; i++) {
		if (scanf("%1022s", S[i] + 1) != 1) return 1;
	}
	if (scanf("%d%d%d%d", &A, &B, &C, &D) != 4) return 1;

	memset(mincost, 0x7f, sizeof(mincost));
	mincost[A][B][4] = 0;
	q[qe++] = (struct q_s){ A, B, 4 };
	while (qs < qe) {
		struct q_s cur = q[qs++];
		int curcost = mincost[cur.y][cur.x][cur.mg];
		for (i = 0; i < 4; i++) {
			int ny = cur.y + d[i][0], nx  = cur.x + d[i][1];
			if (ny <= 0 || H < ny || nx <= 0 || W < nx) continue;
			/* 普通に行く */
			if (S[ny][nx] == '.' || cur.mg == i) {
				if (mincost[ny][nx][4] > curcost) {
					mincost[ny][nx][4] = curcost;
					q[--qs] = (struct q_s){ ny, nx, 4 };
				}
			}
			/* 前蹴りをして行く */
			if (mincost[ny][nx][i] > curcost + 1) {
				mincost[ny][nx][i] = curcost + 1;
				q[qe++] = (struct q_s){ ny, nx, i };
			}
		}
	}
	ans = mincost[C][D][0];
	for (i = 1; i < 5; i++) {
		if (mincost[C][D][i] < ans) ans = mincost[C][D][i];
	}
	printf("%d\n", ans);
	return 0;
}

/*

前蹴りをした後は必ずそっちの方向に移動するとする
→ 前蹴りをした後の移動では、前蹴りをした方向を記録
→ 次回、その方向にはタダで行ける

コスト0とコスト1の遷移がある → 0-1BFS

*/

提出情報

提出日時
問題 D - Takahashi the Wall Breaker
ユーザ mikecat
言語 C (gcc 12.2.0)
得点 400
コード長 1662 Byte
結果 AC
実行時間 186 ms
メモリ 75904 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 4
AC × 34
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt, example_03.txt
All example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 9 ms 22224 KiB
example_01.txt AC 9 ms 22044 KiB
example_02.txt AC 9 ms 22104 KiB
example_03.txt AC 9 ms 22220 KiB
hand_00.txt AC 109 ms 70016 KiB
hand_01.txt AC 120 ms 70036 KiB
hand_02.txt AC 118 ms 69992 KiB
hand_03.txt AC 106 ms 69992 KiB
hand_04.txt AC 100 ms 69900 KiB
hand_05.txt AC 121 ms 70020 KiB
hand_06.txt AC 117 ms 70044 KiB
hand_07.txt AC 90 ms 70044 KiB
hand_08.txt AC 186 ms 75904 KiB
hand_09.txt AC 9 ms 22196 KiB
random_00.txt AC 99 ms 67296 KiB
random_01.txt AC 97 ms 66440 KiB
random_02.txt AC 110 ms 68292 KiB
random_03.txt AC 110 ms 68048 KiB
random_04.txt AC 103 ms 65416 KiB
random_05.txt AC 103 ms 65788 KiB
random_06.txt AC 167 ms 69296 KiB
random_07.txt AC 158 ms 70120 KiB
random_08.txt AC 156 ms 71828 KiB
random_09.txt AC 159 ms 67012 KiB
random_10.txt AC 149 ms 67876 KiB
random_11.txt AC 164 ms 67212 KiB
random_12.txt AC 153 ms 68052 KiB
random_13.txt AC 172 ms 67644 KiB
random_14.txt AC 136 ms 66772 KiB
random_15.txt AC 146 ms 69084 KiB
random_16.txt AC 165 ms 67948 KiB
random_17.txt AC 104 ms 67140 KiB
random_18.txt AC 111 ms 67612 KiB
random_19.txt AC 108 ms 68256 KiB