結果

問題 No.295 hel__world
ユーザー gew1fw
提出日時 2025-06-12 21:11:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,486 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 183,224 KB
最終ジャッジ日時 2025-06-12 21:13:02
合計ジャッジ時間 5,316 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    from collections import defaultdict

    # Read input
    s_alpha = list(map(int, sys.stdin.readline().split()))
    T = sys.stdin.readline().strip()

    # Compute runs of T
    if not T:
        print(0)
        return
    t_runs = []
    prev = T[0]
    t_runs.append(prev)
    for c in T[1:]:
        if c != prev:
            t_runs.append(c)
            prev = c
    K = len(t_runs)
    if K == 0:
        print(0)
        return

    # Group runs by character
    groups = defaultdict(list)
    for idx, c in enumerate(t_runs):
        groups[c].append(idx)

    # Check feasibility and compute a_i for each group
    product = 1
    for c in groups:
        m_c = len(groups[c])
        s = s_alpha[ord(c) - ord('a')]
        if s < m_c:
            print(0)
            return
        d = s - m_c
        x = d // m_c
        r = d % m_c

        # Assign a_i's for each run in the group
        # Since the runs are in the order of t_runs, we need to collect them
        # We'll store a list of a_i's for each run in t_runs order
        a_list = [1 + x + (1 if i < r else 0) for i in range(m_c)]
        for idx_in_group, run_pos in enumerate(groups[c]):
            a = a_list[idx_in_group]
            t_runs[run_pos] = a

    # Compute the product
    product = 1
    for a in t_runs:
        product *= a
        if product > (1 << 62):
            print("hel")
            return

    print(product)

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