We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Your code look like C++, but not Pythonic.
Power of Python - built-in batterys!
Use int(bin_string, 2) to convert string of binary representation: int('101', 2)=5
It allow use bitwise OR (very fast).
For counting '1' in OR-result just do it: bin(or_rslt).count('1')
In sum, it turns to something like this:
Pairs_max_top_lst= [bin(guys_lst[i] | guys_lst[j]).count('1') for i in xrange(N_guys-1) for j in xrange(i+1,N_guys) ]
max_top=max(pairs_max_top)
max_team_num=pairs_max_top.count(max_top)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
ACM ICPC Team
You are viewing a single comment's thread. Return to all comments →
Your code look like C++, but not Pythonic. Power of Python - built-in batterys!
Use
int(bin_string, 2)
to convert string of binary representation:int('101', 2)=5
It allow use bitwise OR (very fast).
For counting '1' in OR-result just do it:
bin(or_rslt).count('1')
In sum, it turns to something like this:
Pairs_max_top_lst=
[bin(guys_lst[i] | guys_lst[j]).count('1')
for i in xrange(N_guys-1)
for j in xrange(i+1,N_guys) ]
max_top=max(pairs_max_top) max_team_num=pairs_max_top.count(max_top)