You are not logged in. Please login at www.codechef.com to post your questions!

×

June Cook Off :ANKPAREN - NZEC in Python For

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

Python : http://www.codechef.com/viewsolution/7261753

C++ : http://www.codechef.com/viewsolution/7262326

asked 22 Jun '15, 12:24

geek_geek's gravatar image

4★geek_geek
43914
accept rate: 16%

edited 22 Jun '15, 13:15

admin's gravatar image

0★admin ♦♦
19.7k350498541


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.

link

answered 22 Jun '15, 14:56

vamsi_ism's gravatar image

4★vamsi_ism
1276
accept rate: 60%

edited 22 Jun '15, 14:56

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.

link

answered 22 Jun '15, 13:35

drj_reddy's gravatar image

3★drj_reddy
176110
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) geek_geek4★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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