結果

問題 No.971 いたずらっ子
ユーザー 双六双六
提出日時 2020-08-04 23:03:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 539 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 299,724 KB
最終ジャッジ日時 2023-08-07 08:08:40
合計ジャッジ時間 7,255 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 539 ms
299,384 KB
testcase_01 AC 539 ms
299,600 KB
testcase_02 AC 412 ms
234,424 KB
testcase_03 AC 459 ms
299,724 KB
testcase_04 AC 441 ms
286,184 KB
testcase_05 AC 464 ms
299,448 KB
testcase_06 AC 349 ms
233,088 KB
testcase_07 AC 106 ms
77,292 KB
testcase_08 AC 191 ms
127,092 KB
testcase_09 AC 187 ms
124,576 KB
testcase_10 AC 99 ms
77,284 KB
testcase_11 AC 90 ms
71,512 KB
testcase_12 AC 91 ms
71,824 KB
testcase_13 AC 95 ms
76,484 KB
testcase_14 AC 123 ms
77,768 KB
testcase_15 AC 98 ms
76,492 KB
testcase_16 AC 96 ms
72,504 KB
testcase_17 AC 91 ms
71,748 KB
testcase_18 AC 92 ms
71,752 KB
testcase_19 AC 90 ms
71,820 KB
testcase_20 AC 90 ms
71,868 KB
testcase_21 AC 91 ms
71,772 KB
testcase_22 AC 91 ms
71,720 KB
testcase_23 AC 91 ms
71,688 KB
testcase_24 AC 90 ms
71,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	H, W = getlist()
	table = []
	for i in range(H):
		l = list(input())
		table.append(l)

	DP = [[INF] * W for i in range(H)]
	DP[0][0] = 0
	for j in range(1, W):
		if table[0][j] == ".":
			DP[0][j] = DP[0][j - 1] + 1
		else:
			DP[0][j] = DP[0][j - 1] + 1 + j

	for i in range(1, H):
		if table[i][0] == ".":
			DP[i][0] = DP[i - 1][0] + 1
		else:
			DP[i][0] = DP[i - 1][0] + 1 + i

	# DP
	for i in range(1, H):
		for j in range(1, W):
			if table[i][j] == ".":
				DP[i][j] = min(DP[i - 1][j], DP[i][j - 1]) + 1
			else:
				DP[i][j] = min(DP[i - 1][j], DP[i][j - 1]) + 1 + i + j


	ans = DP[-1][-1]
	print(ans)

if __name__ == '__main__':
	main()
0