Problem p02735 (python)

Fixed submission:
h,w=map(int,input().split())

m=[input() for i in range(h)]


cnt=[[1000000 for i in range(w)] for j in range(h)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(h):
    for x in range(w):
        if x>0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y>0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[h-1][w-1])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

m=[input() for i in range(w)]




print(0)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

m=[input() for i in range(w)]

cnt=[[1000000 for i in range(h)] for j in range(w)]



print(0)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

m=[input() for i in range(w)]

cnt=[[1000000 for i in range(h)] for j in range(w)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0


print(0)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

m=[input() for i in range(w)]

print("A")
cnt=[[1000000 for i in range(h)] for j in range(w)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(w):
    for x in range(h):
        if x>0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y>0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

m=[input() for i in range(w)]


cnt=[[1000000 for i in range(h)] for j in range(w)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(w):
    for x in range(h):
        if x>0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y>0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

m=[input() for i in range(w)]


cnt=[[1000000 for i in range(h)] for j in range(w)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(w):
    for x in range(h):
        if x>0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y>0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

m=[input() for i in range(w)]


cnt=[[1000000 for i in range(h)] for j in range(w)]

print(cnt)
if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(w):
    for x in range(h):
        if x>0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y>0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[w-1][h-1])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

m=[input() for i in range(w)]


cnt=[[1000000 for i in range(h)]for j in range(w)]


if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(w):
    for x in range(h):
        if x!=0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y!=0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(1)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

m=[input() for i in range(w)]


cnt=[[1000000 for i in range(h)]for j in range(w)]


if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(w):
    for x in range(h):
        if x!=0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y!=0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[w-1][h-1])

Buggy submission (verdict: Runtime Error):
import queue

h,w=map(int,input().split())

m=[input() for i in range(w)]

q=queue.Queue()

cnt=[[1000000 for i in range(h)]for j in range(w)]


if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(w):
    for x in range(h):
        if x!=0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y!=0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[w-1][h-1])

Buggy submission (verdict: Runtime Error):
import queue

h,w=map(int,input().split())

m=[input() for i in range(w)]

q=queue.Queue()

cnt=[[1000000 for i in range(h)]for j in range(w)]


if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(w):
    for x in range(h):
        if x!=0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y!=0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[w-1][h-1])

Buggy submission (verdict: Runtime Error):
import queue

h,w=map(int,input().split())

m=[input() for i in range(w)]
cx=0
cy=0

q=queue.Queue()

cnt=[[10000000 for i in range(h)]for j in range(w)]


if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

while cx!=h-1 or cy!=w-1:
    if cx<h-1:
        q.put([cx+1,cy])
        if m[cy][cx]=="." and m[cy][cx+1]=="#":
            cnt[cy][cx+1]=min(cnt[cy][cx+1],cnt[cy][cx]+1)
        else:
            cnt[cy][cx+1]=min(cnt[cy][cx+1],cnt[cy][cx])
    if cy<w-1:
        q.put([cx,cy+1])
        if m[cy][cx]=="." and m[cy+1][cx]=="#":
            cnt[cy+1][cx]=min(cnt[cy+1][cx],cnt[cy][cx]+1)
        else:
            cnt[cy+1][cx]=min(cnt[cy+1][cx],cnt[cy][cx])
    cx,cy=q.get()


print(cnt[w-1][h-1])

Buggy submission (verdict: Runtime Error):
import queue


h,w=map(int,input().split())

m=[input() for i in range(w)]

q=queue.Queue()


cnt=[[100000000 for i in range(h)] for j in range(w)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

q.put([1,1])

c=[1,1]#[w,h]
while c!=[w,h]:
    c=q.get()
    if c[0]+1<=w:
        q.put([c[0]+1,c[1]])
        if m[c[0]][c[1]-1]=="#":
            cnt[c[0]][c[1]-1]=min(cnt[c[0]][c[1]-1],cnt[c[0]-1][c[1]-1]+1)
        else:
            cnt[c[0]][c[1]-1]=min(cnt[c[0]][c[1]-1],cnt[c[0]-1][c[1]-1])
    if c[1]+1<=h:
        q.put([c[0],c[1]+1])
        if m[c[0]-1][c[1]]=="#":
            cnt[c[0]-1][c[1]]=min(cnt[c[0]-1][c[1]],cnt[c[0]-1][c[1]-1]+1)
        else:
            cnt[c[0]-1][c[1]]=min(cnt[c[0]-1][c[1]],cnt[c[0]-1][c[1]-1])

print(cnt[w-1][h-1])

Buggy submission (verdict: Runtime Error):
import queue


h,w=map(int,input().split())

m=[input() for i in range(w)]

q=queue.Queue()


cnt=[[100000000 for i in range(h)] for j in range(w)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

q.put([1,1])

c=[0,0]#[w,h]
while c!=[w,h]:
    c=q.get()
    if c[0]+1<=w:
        q.put([c[0]+1,c[1]])
        if m[c[0]][c[1]-1]=="#":
            cnt[c[0]][c[1]-1]=min(cnt[c[0]][c[1]-1],cnt[c[0]-1][c[1]-1]+1)
        else:
            cnt[c[0]][c[1]-1]=min(cnt[c[0]][c[1]-1],cnt[c[0]-1][c[1]-1])
    if c[1]+1<=h:
        q.put([c[0],c[1]+1])
        if m[c[0]-1][c[1]]=="#":
            cnt[c[0]-1][c[1]]=min(cnt[c[0]-1][c[1]],cnt[c[0]-1][c[1]-1]+1)
        else:
            cnt[c[0]-1][c[1]]=min(cnt[c[0]-1][c[1]],cnt[c[0]-1][c[1]-1])

print(cnt[h-1][w-1])