You are viewing a single comment's thread. Return to all comments →
def solve(n, k, s): s= [int(x) for x in s] rolling_sum=sum(s[:k+1]) num_pairs=0 for i in range(k,n+k): if s[i-k]: num_pairs+=2*rolling_sum-1 rolling_sum-=1 if i+1<n: rolling_sum+=s[i+1] d=math.gcd(num_pairs, n**2) return f'{int(num_pairs/d)}/{int(n**2/d)}'
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Probability
You are viewing a single comment's thread. Return to all comments →