×

# June Cook Off :ANKPAREN - NZEC in Python For

 0 What causes NZEC in python I submitted a code in python , i tested in Codechef IDE which gave appropriate output when i submitted the same for the problem it gave me an NZEC When i just wrote the same algo code in C++ 4.92 it gave me AC Here is the link asked 22 Jun '15, 12:24 439●14 accept rate: 16% 0★admin ♦♦ 19.7k●350●498●541

 1 Apparently input data of the problem is not according to given format. I too had a similar problem. PS. I didn't read your code, there may be other errors. answered 22 Jun '15, 14:56 127●6 accept rate: 60%
 0 Hi @geek_geek, Only place i can see the posibility of error is using of del on the list on lines 38 and 43. So try like this, # your code goes here def isval(s): xy = 0 for i in s: if(i=='('): xy+=1 else: xy-=1 if(xy<0): return -1 if(xy==0): return 1 else: return -1 def prog(): s = raw_input() #print "##",s k = input() if(isval(s)==-1): if(k==1): print s else: print -1 else: nu = 0 l=len(s) s=list(s) wan = [] for i in xrange(l-1): if(s[i]=='(' and s[i+1]==')'): nu+=2 wan+=[(i,i+1)] if(k>nu): print -1 elif(k>(nu/2)): k-=(nu/2) k-=1 x=wan[-1::-1][k][0] del s[x] print "".join(s) else: k-=1 x=wan[k][1] del s[x] print "".join(s) t = input() for _ in xrange(t): try: prog() except Exception: pass  If the solution doesn't give NZEC, proramatically it wouldn't throw NZEC, then we can focus on 'del' part try to handle it in different way if length of list greater than w then delete that element. answered 22 Jun '15, 13:35 176●1●10 accept rate: 8% Handling del in a different way doesnt help !! i think it has to be with something else (22 Jun '15, 15:49)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,901
×418
×122

question asked: 22 Jun '15, 12:24

question was seen: 1,009 times

last updated: 22 Jun '15, 15:49