結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
双六
|
| 提出日時 | 2020-08-04 23:03:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 563 ms / 2,000 ms |
| コード長 | 886 bytes |
| コンパイル時間 | 423 ms |
| コンパイル使用メモリ | 82,560 KB |
| 実行使用メモリ | 298,112 KB |
| 最終ジャッジ日時 | 2024-11-07 11:46:36 |
| 合計ジャッジ時間 | 6,451 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
# 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()
双六