move

 avatar
unknown
python
3 years ago
1.2 kB
2
Indexable
s=input().split()
r=int(s[0])
c=int(s[1])
kk=int(s[2])
m=int(s[3])
pl=[[-1]*(c+2) for i in range(r+2)]
for i in range(r):
    u=input().split()
    for k in range(c):
        pl[i+1][k+1]=int(u[k])
#print(pl)
st=[[-1]*(c+2) for i in range(r+2)]
for i in range(r+2):
    for k in range(c+2):
        st[i][k]=pl[i][k]
for i in range(m):
    for u in range(r):
        for j in range(c):
            if pl[u+1][j+1]>=0:
                give=(pl[u+1][j+1])//kk
                for uu in range(3):
                    for jj in range(3):
                        if pl[u+uu][j+jj]>=0 and (uu+jj)%2==1 :
                            st[u+uu][j+jj]=st[u+uu][j+jj]+give
                            st[u+1][j+1]=st[u+1][j+1]-give
                            #print(pl[u+1][j+1],give)
    # 在第i天結束時,將遷移後的結果複製回二維陣列pl
    for u in range(r):
        for j in range(c):
            pl[u+1][j+1] = st[u+1][j+1]
#print(st)
sm=101
bi=0
for i in range(r):
    for k in range(c):
        if st[i+1][k+1]>0:
            if st[i+1][k+1]>bi:
                bi=st[i+1][k+1]
            if st[i+1][k+1]<sm:
                sm=st[i+1][k+1]
print(sm)
print(bi)