Reputation: 93
I have been trying to submit this program to SPOJ but it keeps giving me an NZEC. I have tested it in my computer and it returns the corect results. Can anybody tell me what's wrong with it? This is how the input looks like: http://www.spoj.com/problems/SERVS/ and this is my code:
import numpy as np
import sys
input=sys.stdin.readlines()
w = []
for line in input:
lst = line.strip().split(' ')
w.append(int(lst[0]))
z=w[1:]
size = len(z)
M = np.zeros((len(z),len(z)))
for i in range(size-1, -1, -1):
for j in range(size-1, i-1, -1):
if i == size-1:
M[i,j] = z[i]
else:
if j > i:
M[i,j] = M[i+1,j] + [j-i]
elif j == i:
M[i,j] = z[i] + M[j+1, (j+1):].min()
cost = int(M[j, j:].min())
print cost
Any help is much appreciated.
Upvotes: 1
Views: 251
Reputation: 304167
I don't think SPOJ supports numpy. Submitting just this:
import numpy
fails with a NZEC (probably an ImportError)
You should also guard against an empty line at the end of the input
for line in input:
lst = line.strip().split(' ')
if not lst: break
w.append(int(lst[0]))
Upvotes: 2