Editorial for 第2回卬高杯 H問題 - Reft and Light
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Python
Python3
def modinv(a):
mod=127237991
power=mod-2
res = 1
while power>0:
if power%2:
res=res*a%mod
a=a*a%mod
power//=2
return res
def main():
mod=127237991
N ,A ,B= map(int,input().split())
T=input()
r=T.count("R")
l=T.count("L")
p=A*modinv(B)%mod
pW=(1-p)%mod
ans=0
c0=1
for i in range(l+r):c0=c0*pW%mod
ans+=c0
for i in range(min(l,r)):
c0=c0*(l-i)*(r-i)*p*p%mod
c0=c0*modinv(i+1)*modinv(i+1)*modinv(pW)*modinv(pW)%mod
ans=(ans+c0)%mod
print(ans)
if __name__ == '__main__':
main()
Comments