結果

問題 No.603 hel__world (2)
ユーザー gew1fw
提出日時 2025-06-12 14:44:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,009 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 140,896 KB
最終ジャッジ日時 2025-06-12 14:45:16
合計ジャッジ時間 4,285 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**6 + 3

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

# Create T_comp by removing consecutive duplicates
prev_char = None
T_comp = []
for c in T:
    if c != prev_char:
        T_comp.append(c)
        prev_char = c

# Count occurrences of each character in T_comp
from collections import defaultdict
char_counts = defaultdict(int)
for c in T_comp:
    char_counts[c] += 1

# Check if all characters in T_comp have sufficient counts in S
result = 1
for char in char_counts:
    required = char_counts[char]
    available = S_counts[ord(char) - ord('a')]
    if available < required:
        print(0)
        exit()
    k = available - required
    base, remainder = divmod(k, required)
    # Calculate contribution (base+1)^(required - remainder) * (base+2)^remainder mod MOD
    part1 = pow(base + 1, required - remainder, MOD)
    part2 = pow(base + 2, remainder, MOD)
    contribution = (part1 * part2) % MOD
    result = (result * contribution) % MOD

print(result)
0