結果

問題 No.295 hel__world
コンテスト
ユーザー titia
提出日時 2026-06-26 03:42:42
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 1,251 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 186 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 137,800 KB
最終ジャッジ日時 2026-06-26 03:43:22
合計ジャッジ時間 11,865 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 34 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

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):
    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
    rest=k-sum(L)

    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")
else:
    print(ANS[0])

    



    
0