結果

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

ソースコード

diff #

from collections import defaultdict

def main():
    S_counts = list(map(int, input().split()))
    T = input().strip()
    
    # Process T into runs
    R_T = []
    prev_char = None
    for c in T:
        if c != prev_char:
            R_T.append(c)
            prev_char = c
    
    # Count frequency of each character in R_T
    freq = defaultdict(int)
    for c in R_T:
        freq[c] += 1
    
    # Check if any character's frequency exceeds S's count
    for c in freq:
        idx = ord(c) - ord('a')
        if freq[c] > S_counts[idx]:
            print(0)
            return
    
    # Calculate the product
    product = 1
    for c in freq:
        idx = ord(c) - ord('a')
        m = freq[c]
        s = S_counts[idx]
        q, r = divmod(s, m)
        term = ( (q + 1) ** r ) * ( q ** (m - r) )
        product *= term
        if product >= (1 << 62):
            print("hel")
            return
    
    print(product)

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