結果

問題 No.603 hel__world (2)
ユーザー gew1fw
提出日時 2025-06-12 21:13:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,374 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 156,344 KB
最終ジャッジ日時 2025-06-12 21:15:42
合計ジャッジ時間 4,215 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**6 + 3

def main():
    import sys
    input = sys.stdin.read().split()
    s_params = list(map(int, input[:26]))
    T = input[26].strip()

    # Compute runs of T
    runs = []
    if not T:
        print(0)
        return
    current = T[0]
    runs.append(current)
    for c in T[1:]:
        if c != runs[-1]:
            runs.append(c)
    
    # Check for consecutive same runs
    for i in range(len(runs) - 1):
        if runs[i] == runs[i+1]:
            print(0)
            return
    
    # Count m_c for each character in runs
    from collections import defaultdict
    m = defaultdict(int)
    for c in runs:
        m[c] += 1
    
    # Read S parameters: a to z are s_params[0] to s_params[25]
    s_dict = {chr(ord('a') + i): s_params[i] for i in range(26)}
    
    # Check for each c: m_c <= s_dict[c]
    for c in m:
        if m[c] > s_dict[c]:
            print(0)
            return
    
    # For each c, compute E, a, r, and contribution
    result = 1
    for c in m:
        s_c = s_dict[c]
        m_c = m[c]
        E = s_c - m_c
        if E < 0:
            print(0)
            return
        a = E // m_c
        r = E % m_c
        contribution = pow(a + 2, r, MOD) * pow(a + 1, m_c - r, MOD)
        contribution %= MOD
        result = (result * contribution) % MOD
    
    print(result)

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