結果

問題 No.295 hel__world
コンテスト
ユーザー titia
提出日時 2026-06-26 03:53:28
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 2,170 ms / 5,000 ms
コード長 2,689 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 213 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 137,740 KB
最終ジャッジ日時 2026-06-26 03:53:45
合計ジャッジ時間 15,760 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from heapq import heappop,heappush

A=list(map(int,input().split()))
T=input().strip()
T2=[ord(t)-97 for t in T]

B=[0]*26

for t in T2:
    B[t]+=1

for i in range(26):
    if A[i]<B[i]:
        print(0)
        exit()

LIST=[[] for i in range(26)]

count=0
now=-1

for i in range(len(T2)):
    if i-1>=0 and T2[i]==T2[i-1]:
        count+=1
    else:
        if now!=-1:
            LIST[now].append(count)

        count=1
        now=T2[i]

if now!=-1:
    LIST[now].append(count)

#print(LIST)

def calc(L,k):
    rest=k-sum(L)
    if len(L)==1:
        x=L[0]
        c=k
        for i in range(x):
            ANS[0]=ANS[0]*c
            c-=1

        c=1
        for i in range(x):
            ANS[0]=ANS[0]//c
            c+=1

        return

    if len(L)==2:
        MIN=0
        MAX=rest

        while MAX-MIN>5:
            mid1=MIN+(MAX-MIN)//3
            mid2=MIN+(MAX-MIN)//3*2


            score=1
            c=mid1+L[0]
            for i in range(L[0]):
                score=score*c
                c-=1

            c=(rest-mid1)+L[1]
            for i in range(L[1]):
                score=score*c
                c-=1

            score2=1
            c=mid2+L[0]
            for i in range(L[0]):
                score2=score2*c
                c-=1

            c=(rest-mid2)+L[1]
            for i in range(L[1]):
                score2=score2*c
                c-=1

            if score>score2:
                MAX=mid2
            else:
                MIN=mid1

        ANSX=-1

        for mid in range(MIN,MAX+1):
            score=1
            c=mid+L[0]
            for i in range(L[0]):
                score=score*c
                c-=1

            c=(rest-mid)+L[1]
            for i in range(L[1]):
                score=score*c
                c-=1

            ANSX=max(score,ANSX)

        c=1
        for i in range(L[0]):
            ANSX=ANSX//c
            c+=1

        c=1
        for i in range(L[1]):
            ANSX=ANSX//c
            c+=1

        ANS[0]=ANS[0]*ANSX

        return
            

    if len(L)>=3 and k>=10**8:
        print("hel")
        exit()
    

    Q=[]

    for x in L:
        heappush(Q,(-(x+1),x+1,1))

    for i in range(rest):
        #print(Q)
        com,x,y=heappop(Q)

        ANS[0]=ANS[0]*x//y

        x+=1
        y+=1
        heappush(Q,(-x/y,x,y))

        if ANS[0]>=(2**62):
            print("hel")
            exit()


ANS=[1]

for i in range(26):
    if LIST[i]==[]:
        continue
    calc(LIST[i],A[i])

    if ANS[0]>=(2**62):
        print("hel")
        exit()

if ANS[0]>=(2**62):
    print("hel")
else:
    print(ANS[0])

    



    
0