Which test case my code is failing? (TYPING|python3.6)

Question code: TYPING

My code:

s=set()
l=["d","f"]
r=["j","k"]
for i in range (int(input())):
    a=[]
    for j in range (int(input())):
        str1=input()
        t=0
        li=list(str1)
        b=len(str1)
        if str1 not in s:
            s.add(str1)
            for x in range(0,b-1):
                if (li[x] in l and li[x+1] in l) or (li[x] in r and li[x+1] in r):
                    t=t+1
            ans =(b+t)*0.2 #this is actually (b-t)*0.2 +t*0.4
            a.append(ans)
        else:
            for x in range(0,b-1):
                if (li[x] in l and li[x+1] in l) or (li[x] in r and li[x+1] in r):
                    t=t+1
            ans =(b+t)*0.1
            a.append(ans)
    fans=sum(a)*10
    print (int(fans))
1 Like

I tried to understand what’s happening when “str1 in s” and “not in s” but it’s too late here and I’m sleepy. Here check my solution, everything is clear there: solution link

Your system for adding a time penalty per same-hand letter pair seems accurate.

You would do better to work in integers throughout, basically adjusting so that your units of time are deciseconds (tenths of a second). I don’t think that it is causing a problem here, with low numbers, but you could avoid the issue completely.

However your actual main problem is that you don’t reset your set s of known words between test cases. So encountering a word for the first time in a test case, you may score it like it is not the first time.

Thanks a lot!

//