結果

問題 No.295 hel__world
ユーザー mkawa2mkawa2
提出日時 2021-03-16 13:42:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,525 ms / 5,000 ms
コード長 1,890 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 211,968 KB
最終ジャッジ日時 2024-04-25 12:20:41
合計ジャッジ時間 10,737 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,864 KB
testcase_01 AC 39 ms
52,864 KB
testcase_02 AC 39 ms
53,248 KB
testcase_03 AC 39 ms
52,992 KB
testcase_04 AC 39 ms
53,120 KB
testcase_05 AC 39 ms
52,864 KB
testcase_06 AC 40 ms
52,864 KB
testcase_07 AC 38 ms
52,992 KB
testcase_08 AC 38 ms
52,992 KB
testcase_09 AC 37 ms
52,736 KB
testcase_10 AC 38 ms
52,736 KB
testcase_11 AC 38 ms
52,736 KB
testcase_12 AC 38 ms
52,736 KB
testcase_13 AC 39 ms
53,248 KB
testcase_14 AC 44 ms
52,992 KB
testcase_15 AC 40 ms
53,248 KB
testcase_16 AC 40 ms
52,992 KB
testcase_17 AC 40 ms
52,864 KB
testcase_18 AC 38 ms
52,864 KB
testcase_19 AC 40 ms
52,864 KB
testcase_20 AC 42 ms
53,120 KB
testcase_21 AC 41 ms
52,992 KB
testcase_22 AC 40 ms
52,992 KB
testcase_23 AC 41 ms
53,248 KB
testcase_24 AC 41 ms
53,120 KB
testcase_25 AC 57 ms
64,512 KB
testcase_26 AC 47 ms
59,904 KB
testcase_27 AC 408 ms
75,776 KB
testcase_28 AC 1,763 ms
76,288 KB
testcase_29 AC 3,525 ms
76,544 KB
testcase_30 AC 40 ms
53,504 KB
testcase_31 AC 40 ms
53,120 KB
testcase_32 AC 228 ms
211,584 KB
testcase_33 AC 210 ms
211,968 KB
testcase_34 AC 236 ms
211,840 KB
testcase_35 AC 40 ms
52,992 KB
testcase_36 AC 41 ms
52,608 KB
testcase_37 AC 39 ms
52,608 KB
testcase_38 AC 40 ms
52,992 KB
testcase_39 AC 39 ms
52,864 KB
testcase_40 AC 40 ms
53,248 KB
testcase_41 AC 39 ms
53,120 KB
testcase_42 AC 40 ms
53,248 KB
testcase_43 AC 38 ms
52,736 KB
testcase_44 AC 42 ms
52,736 KB
testcase_45 AC 39 ms
53,120 KB
testcase_46 AC 39 ms
52,992 KB
testcase_47 AC 39 ms
53,120 KB
testcase_48 AC 39 ms
53,120 KB
testcase_49 AC 42 ms
52,992 KB
testcase_50 AC 58 ms
66,432 KB
testcase_51 AC 370 ms
76,160 KB
testcase_52 AC 131 ms
76,288 KB
testcase_53 AC 61 ms
68,480 KB
testcase_54 AC 62 ms
68,480 KB
testcase_55 AC 64 ms
67,968 KB
testcase_56 AC 64 ms
68,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

from heapq import *

def RLE(s):
    cc=[]
    ww=[]
    pc=s[0]
    w=0
    for c in s:
        if c==pc:w+=1
        else:
            cc.append(pc)
            ww.append(w)
            w=1
            pc=c
    cc.append(pc)
    ww.append(w)
    return cc,ww

lim=1<<62
aa=LI()
s=BI()

cc,ll=RLE(s)

cnt=[[] for _ in range(26)]
for c,l in zip(cc,ll):
    cnt[c-97].append(l)
# print(cnt)

ans=1
for i,(a,cc) in enumerate(zip(aa,cnt)):
    if not cc:continue
    s=sum(cc)
    if a<s:
        print(0)
        exit()
    aa[i]=a-s

for i, (a, cc) in enumerate(zip(aa, cnt)):
    if not cc or a==0:continue

    if a>10000000 and sum(cc)>2:
        print("hel")
        exit()

    if sum(cc)==1:
        cur=a+1
    elif sum(cc)==2:
        a += 2
        if len(cc)==1:
            cur=a*(a-1)//2
        else:
            cur=(a//2)*(a-a//2)
    else:
        hp=[]
        cur=1
        for c in cc:
            heappush(hp,(-(c+1)/(c-c+1),c,c))
            cur=1
        for _ in range(a):
            m,n,r=heappop(hp)
            cur=cur*(n+1)//(n-r+1)
            heappush(hp,(-(n+2)/(n-r+2),n+1,r))
    ans*=cur
    if ans>=lim:
        print("hel")
        exit()

print(ans)
0