if (ls[i]*ls[j]) in ls[j+1:]:
count+=1
I think you should add the number of occurrence instead of just 1
Also, isn't this solution too slow for large data set?
Ho Wei Hong <[email protected]> 于2019年3月25日周一 上午7:22写道:
> Sorry to disturb this group again.
>
> But i can't seem to figure out where i got wrong. I feed in a few test
> case and everything works, but the checker seems to say WA(Wrong Answer)
>
>
> Hope somebody can point me to the right direction again. Thank you
>
>
> https://codingcompetitions.withgoogle.com/kickstart/round/0000000000051066/0000000000051187
>
> def sol(ls):
> ls.sort()
> count = 0
> if ls[1]==0:
> temp = ls.count(0)
> if temp>=3:
> #number of 0 Choose 3
> count+=temp*(temp-1)*(temp-2)//6
> #(Temp choose 2 times number of non-zeroes)
> count+= temp*(temp-1)//2*(len(ls)-temp)
>
> for i in range(len(ls)-2):
> if ls[i]==0:
> continue #ignore zeroes
> for j in range(i+1,len(ls)-1):
> if (ls[i]*ls[j]) in ls[j+1:]:
> count+=1
> return count
>
> def main():
> for i in range(int(input())):
> a = int(input())
> y = input()
> ls= [int(x) for x in y.split(' ')]
> c = sol(ls)
> print("Case #{}: {}".format(i+1, c))
> return
>
> main()
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/6a0352be-f38b-4539-be80-265f50c41d56%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/CAGDEU-Js%2BuJ1_cndJBTGHY0hNvtEaVHHPb0%3DP7FHrx%2BUko8Ngw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.