1 / 2
Apr 2019

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

    Apr '19
  • last reply

    Apr '19
  • 1

    reply

  • 1.1k

    views

  • 2

    users

  • 1

    link

And on ideone, did you give it any input? Be sure to put something in the Input Box, and don’t forget the 0 to signal the end of the test cases.

When I gave it the input from the problem, it gave me the expected output.