結果

問題 No.603 hel__world (2)
ユーザー lam6er
提出日時 2025-04-16 00:00:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 758 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 140,944 KB
最終ジャッジ日時 2025-04-16 00:02:34
合計ジャッジ時間 3,626 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**6 + 3

# Read input
S_alpha = list(map(int, input().split()))
T = input().strip()

# Compress T into groups
prev_char = None
groups = []
for c in T:
    if c != prev_char:
        groups.append(c)
        prev_char = c

# Count the number of groups for each character
from collections import defaultdict
group_counts = defaultdict(int)
for c in groups:
    group_counts[c] += 1

result = 1

for c in group_counts:
    k = group_counts[c]
    idx = ord(c) - ord('a')
    s = S_alpha[idx]
    
    if s < k:
        print(0)
        exit()
    
    m = s - k
    base, r = divmod(m, k)
    
    a = (base + 2) % MOD
    b = (base + 1) % MOD
    
    term = (pow(a, r, MOD) * pow(b, k - r, MOD)) % MOD
    result = (result * term) % MOD

print(result)
0