My first DP prob on SPOJ. I was excited to get it on my IDE (jupyter). I solved it. But the submitted solution is giving error on SPOJ
Here’s the problem ACODE - AlphaCode - ACODE - AlphaCode3
The error ‘ideone’ gives is ‘standard input is empty’, ‘standard output is empty’. and ‘EOF reached while reading file’.
Here’s the solution that works perfectly on my PC but not on SPOJ. The first is just the function that does all the computation. The helper code ( which is probably what gives the error) starts at the bottom with the while loop :
def dp(s):
codeLength = len(str(s))
s= str(s)
if '0' in s:
return 0
m = [0]*(1+ len(s))
m[0] = 0
m[1] = 1
if codeLength >= 2:
if int(s[:2]) > 26:
m[2] = 1
else:
m[2] = 2
for i in range(2,len(s)):
if int(s[i-1:i+1]) > 26:
m[i+1] = m[i]
else:
m[i+1] = m[i-1] + m[i]
#print('i-2 is : ', i-2)
return m[codeLength]
while True:
t = input()
if t!=‘0’:
print(dp(t))
else:
break
created
last reply
- 1
reply
- 1.1k
views
- 2
users
- 1
link