I am having trouble solving the problem The Awakening of the Force of the URI.
Long ago, in a galaxy far, far away ...
Following the decline of the Empire, scrap yards are scattered all over the universe searching for a saber of lost light. Everyone knows that a light saber emits a specific wave pattern: 42 surrounded by 7 em all around. You have a wave sensor that sweeps a terrain with N x M cells. See the example below for a 4 x 7 terrain with a light on it (position (2, 4)).
Youshouldwriteaprogramthat,givenaNxMterrain,looksfor bythelightsaberpatternonit.Noscanhasmorethanone lightsaberpattern.
Entry
ThefirstlineoftheentryhastwopositivenumbersNandM, representing,respectively,thenumberofrowsandcolumns sweptintheground(3≤N,M≤1000).EachofthenextNlines hasMintegers,whichdescribethevaluesreadineachcellofthe (-100≤Tij≤100,for1≤i≤Nand1≤j≤M).
Output
Theoutputisasinglelinewith2XandYintegersseparatedbya space.Theyrepresentthecoordinate(X,Y)ofthelightsaber,if found.Iftheterraindoesnothavealightsaberpattern,XandYare bothzero.
Ibasicallysolvedmostoftheproblemanditworksfinewithsmallinputs,buttheyareextremelylargeinputsforexample1000x1000whichendupgivingmeawrongoutput.
AsforexamplethefirstUdebugtestcase: link
I realized that not all values are being stored inside the array, but I have no idea how to circumvent this detail.
Follow my code:
l = input().split()
y, x = int(l[0]), int(l[1])
m=[[0 for i in range(y)]for j in range (x)]
for i in range(y):
m[i] = input().split()
t = t2 = 0
for i in range(y):
for j in range(x):
m[i][j] = int(m[i][j])
for i in range(1, y-1):
for j in range(1, x-1):
if m[i][j] == 42:
if m[i-1][j-1] == 7 and m[i-1][j] == 7 and m[i-1][j+1] == 7:
if m[i][j-1] == 7 and m[i][j + 1] == 7:
if m[i+1][j-1] == 7 and m[i+1][j] == 7 and m[i+1][j+1] == 7:
t = i+1
t2 = j+1
print(t, t2)
It is very likely that I do not have to store all those values since I would consume a lot of memory (trying to solve the problem in the most varied ways I have crashed the computer countless times), I can not imagine any way to deal with it. >