Problem p02735 (python)

Fixed submission:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
dp = [[float("inf")]*w for _ in range(h)]
if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for i in range(h):
    for j in range(w):
        if i+1 < h:
            count1 = dp[i][j]
            if s[i][j] == "." and s[i+1][j] == "#":
                count1 += 1
            dp[i+1][j] = min(dp[i+1][j], count1)
        if j+1 < w:
            count2 = dp[i][j]
            if s[i][j] == "." and s[i][j+1] == "#":
                count2 += 1
            dp[i][j+1] = min(dp[i][j+1], count2)
print(dp[h-1][w-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
dp = [[float("inf")]*w for _ in range(h)]
if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for j in range(h):
    for i in range(w):
        if i+1 < w:
            count1 = dp[i][j]
            if s[i][j] == "." and s[i+1][j] == "#":
                count1 += 1
            dp[i+1][j] = min(dp[i+1][j], count1)
        if j+1 < h:
            count2 = dp[i][j]
            if s[i][j] == "." and s[i][j+1] == "#":
                count2 += 1
            dp[i][j+1] = min(dp[i][j+1], count2)
print(dp[h-1][w-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

dp = [[float("inf")]*w for _ in range(h)]
if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

for j in range(h):
    for i in range(w):
        if i+1 < w:
            count1 = dp[i][j]
            if s[i][j] == "." and s[i+1][j] == "#":
                count1 += 1
            dp[i+1][j] = min(dp[i+1][j], count1)
        if j+1 < h:
            count2 = dp[i][j]
            if s[i][j] == "." and s[i][j+1] == "#":
                count2 += 1
            dp[i][j+1] = min(dp[i][j+1], count2)
print(dp[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
dp = [[float("inf")]*w for _ in range(h)]
if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for j in range(h):
    for i in range(w):
        if i+1 < w:
            count1 = dp[i][j]
            if s[i][j] == "." and s[i+1][j] == "#":
                count1 += 1
            dp[i+1][j] = min(dp[i+1][j], count1)
        if j+1 < h:
            count2 = dp[i][j]
            if s[i][j] == "." and s[i][j+1] == "#":
                count2 += 1
            dp[i][j+1] = min(dp[i][j+1], count2)
print(dp[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
count = 0
if s[0][0] == "#":
    count = 1

dp = [[100000]*w for _ in range(h)]
dp[0][0] = count
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for j in range(h):
    for i in range(w):
        if i+1 < w:
            count1 = dp[i][j]
            if s[i][j] == "." and s[i+1][j] == "#":
                count1 += 1
            dp[i+1][j] = min(dp[i+1][j], count1)
        if j+1 < h:
            count2 = dp[i][j]
            if s[i][j] == "." and s[i][j+1] == "#":
                count2 += 1
            dp[i][j+1] = min(dp[i][j+1], count2)
print(dp[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input() for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
count = 0
if s[0][0] == "#":
    count = 1

dp = [[100000]*w for _ in range(h)]
dp[0][0] = count
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for j in range(h):
    for i in range(w):
        if i+1 < w:
            count1 = dp[i][j]
            if s[i][j] == "." and s[i+1][j] == "#":
                count1 += 1
            dp[i+1][j] = min(dp[i+1][j], count1)
        if j+1 < h:
            count2 = dp[i][j]
            if s[i][j] == "." and s[i][j+1] == "#":
                count2 += 1
            dp[i][j+1] = min(dp[i][j+1], count2)
print(dp[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input() for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
count = 0
if s[0][0] == "#":
    count = 1

dp = [[100000 for _ in range(w)] for _ in range(h)]
dp[0][0] = count
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for j in range(h):
    for i in range(w):
        if i+1 < w:
            if s[i][j] == "." and s[i+1][j] == "#":
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1)
            else:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        if j+1 < h:
            if s[i][j] == "." and s[i][j+1] == "#":
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
            else:
                dp[i][j+1] = min(dp[i][j+1], dp[i][j])
print(dp[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input() for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
count = 0
if s[0][0] == "#":
    count += 1

dp = [[100000]*w for _ in range(h)]
dp[0][0] = count
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for j in range(h):
    for i in range(w):
        if i+1 < w:
            if s[i][j] == "." and s[i+1][j] == "#":
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1)
            else:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        if j+1 < h:
            if s[i][j] == "." and s[i][j+1] == "#":
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
            else:
                dp[i][j+1] = min(dp[i][j+1], dp[i][j])
print(dp[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input() for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
count = 0
if s[0][0] == "#":
    count += 1

dp = [[100000]*w for _ in range(h)]
dp[0][0] = count
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for i in range(w):
    for j in range(h):
        if i+1 <= w-1:
            if s[i][j] == "." and s[i+1][j] == "#":
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1)
            else:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        if j+1 <= h-1:
            if s[i][j] == "." and s[i][j+1] == "#":
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
            else:
                dp[i][j+1] = min(dp[i][j+1], dp[i][j])
print(dp[w-1][h-1])