Or just follow the initial template and use input().
Hi i’m having an issue for the first example
I’m creating a dictionnary to get all coordinates of everything.
then at last i make a for loop to search value 0 and print out coordinate
Here’s my code (Python beginner)
width = int(input()) # the number of cells on the X axis
height = int(input()) # the number of cells on the Y axis
matrix={}
for y in range(height):
line = input() # width characters, each either 0 or .
for x in range(len(line)):
if line[x]=="0":
matrix.update({str(x)+","+str(y):"0"})
else:
matrix.update({str(x)+","+str(y):"-1"})
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
print("debug matrix : "+str(matrix),file=sys.stderr)
out=""
for coord,value in matrix.items():
if value == "0":
temp=coord.split(",")
out=out+" "+" ".join(temp)
# Three coordinates: a node, its right neighbor, its bottom neighbor
print(out[1:]) #suppress initial space
but when running, i have this error :
Timeout: Only 1 node has been computed.
but the final output is right , i have the right answer : 0 0 1 0 0 1
why ?
You have to output one line for each node, so the correct answer for the first test consists of 3 lines:
0 0 1 0 0 1
1 0 -1 -1 -1 -1
0 1 -1 -1 -1 -1