I have written a program for the question Domino Solitaire on CODECHEF in python. If I take number of columns greater than 2920 then this runtime error shows -
Process finished with exit code -1073741571 (0xC00000FD)
But my program works well for lesser number of columns.
Here is my code -
import sys
sys.setrecursionlimit(10000)
def vs(i):
return abs(row1[i] - row2[i])
def hs(i):
return abs(row1[i] - row1[i+1]) + abs(row2[i] - row2[i+1])
n = int(input())
row1 = list(map(int, input().split()))
row2 = list(map(int, input().split()))
memoiz = [[-1, -1] for x in range(n)]
def tileit(i=0):
if i == (n-2):
memoiz[i][0] = vs(i) + vs(i+1)
memoiz[i][1] = hs(i)
return max(memoiz[i][0], memoiz[i][1])
elif i == (n-1):
memoiz[i][0] = vs(i)
return memoiz[i][0]
if memoiz[i][0] != -1:
max_vs = memoiz[i][0]
else:
max_vs = vs(i) + tileit(i+1)
memoiz[i][0] = max_vs
if memoiz[i][1] != -1:
max_hs = memoiz[i][1]
else:
max_hs = hs(i) + tileit(i+2)
memoiz[i][1] = max_hs
return max(max_vs, max_hs)
print(tileit())
The memoiz
list store the maximum vertical score and horizontal score possible from i
th tile (starting from 0)
vs(i)
calculates the vertical tile score of i
th tile
hs(i)
calculates the horizontal tile score of i
th tile
If I add print(i)
inside the tileit()
function on its first line then it prints upto 2919
and then stops for a moment and shows this error.
User contributions licensed under CC BY-SA 3.0