結果

問題 No.295 hel__world
ユーザー lam6er
提出日時 2025-04-15 22:47:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,202 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 82,088 KB
実行使用メモリ 158,384 KB
最終ジャッジ日時 2025-04-15 22:48:52
合計ジャッジ時間 4,338 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 34 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

def main():
    S_alpha = list(map(int, sys.stdin.readline().split()))
    T = sys.stdin.readline().strip()
    
    if not T:
        print(0)
        return
    
    # Split T into runs
    runs = [T[0]]
    for c in T[1:]:
        if c != runs[-1]:
            runs.append(c)
    
    # Count occurrences of each character in runs
    m_c = defaultdict(int)
    for c in runs:
        m_c[c] += 1
    
    # Check if each character in runs has sufficient count
    for c in m_c:
        idx = ord(c) - ord('a')
        if S_alpha[idx] < m_c[c]:
            print(0)
            return
    
    product = 1
    threshold = (1 << 62)
    
    for c in m_c:
        idx = ord(c) - ord('a')
        s_total = S_alpha[idx]
        m = m_c[c]
        s_remaining = s_total - m
        
        if s_remaining < 0:
            print(0)
            return
        
        q, r = divmod(s_remaining, m)
        term = pow(q + 2, r) * pow(q + 1, m - r)
        product *= term
        
        if product >= threshold:
            print("hel")
            return
    
    print("hel" if product >= threshold else product)

if __name__ == "__main__":
    main()
0