Question: def simulate _ water _ flow ( matrix ) : n = len ( matrix ) water _ level = matrix [ n / /
def simulatewaterflowmatrix:
n lenmatrix
waterlevel matrixn n
while True:
for i in rangen:
for j in rangen:
if matrixij waterlevel:
if i and matrixi j:
matrixi jW
if i n and matrixi j:
matrixi jW
if j and matrixij :
matrixij W
if j n and matrixij :
matrixij W
if allcell for row in matrix for cell in row:
break
waterlevel
return matrix
# Input reading
n intinput
terrainmatrix listmapint inputsplit for in rangen
# Call the simulation function
resultmatrix simulatewaterflowterrainmatrix
# Print the result
for row in resultmatrix:
printjoinmapstr row
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
