結果

問題 No.603 hel__world (2)
ユーザー chocoruskchocorusk
提出日時 2020-02-23 17:06:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,241 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 147,412 KB
最終ジャッジ日時 2024-04-18 10:56:46
合計ジャッジ時間 7,395 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 185 ms
97,392 KB
testcase_01 AC 170 ms
90,176 KB
testcase_02 AC 387 ms
91,484 KB
testcase_03 AC 192 ms
90,560 KB
testcase_04 AC 206 ms
90,420 KB
testcase_05 AC 198 ms
90,796 KB
testcase_06 AC 134 ms
89,736 KB
testcase_07 AC 242 ms
90,872 KB
testcase_08 AC 148 ms
89,984 KB
testcase_09 AC 150 ms
89,624 KB
testcase_10 AC 183 ms
90,560 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from decimal import *
from fractions import Fraction
getcontext().prec=40
mod=10**6+3
invs=[0]*mod
invs[1]=1
for i in range(2, mod):
    invs[i]=mod-invs[mod%i]*(mod//i)%mod
def solve(x, v):
    m=len(v)
    if m==0:
        return 1
    s=sum(v)
    if x<s:
        return 0
    elif x==s:
        return 1
    l=Decimal(1)
    r=Decimal(max(v)+2)
    for _ in range(100):
        mid=(l+r)/Decimal(2)
        cnt=0
        for a in v:
            cnt+=int(Decimal(a)/(mid-Decimal(1)))
        if cnt<x-s:
            r=mid
        else:
            l=mid
    ret=1
    cnt=0
    f=Fraction(10**19, 1)
    for a in v:
        k=int(Decimal(a)/(l-Decimal(1)))
        f=min(f, Fraction(a+k, k))
        cnt+=k
        for i in range(a):
            ret=ret*(k+i+1)*invs[i+1]%mod
    p=f.numerator
    q=f.denominator
    ret*=pow(q, cnt-(x-s), mod)*pow(p, mod-1-(cnt-(x-s))%(mod-1), mod)
    ret%=mod
    return ret
v=[[] for i in range(26)]
x=list(map(int, input().split()))
t=input()
n=len(t)
cnt=1
for i in range(1, n):
    if t[i]!=t[i-1]:
        v[ord(t[i-1])-ord('a')].append(cnt)
        cnt=0
    cnt+=1
v[ord(t[n-1])-ord('a')].append(cnt)
ans=1
for i in range(26):
    a=solve(x[i], v[i])
    #print(a)
    ans=ans*a%mod
print(ans)
0