結果
| 問題 | No.603 hel__world (2) | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 19:38:50 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,353 bytes | 
| コンパイル時間 | 192 ms | 
| コンパイル使用メモリ | 82,280 KB | 
| 実行使用メモリ | 163,896 KB | 
| 最終ジャッジ日時 | 2025-06-12 19:39:23 | 
| 合計ジャッジ時間 | 3,671 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 WA * 20 | 
ソースコード
MOD = 10**6 + 3
# Read input
s_counts = list(map(int, input().split()))
t = input().strip()
# Function to compress the string T
def compress(s):
    if not s:
        return []
    compressed = [s[0]]
    for c in s[1:]:
        if c != compressed[-1]:
            compressed.append(c)
    return compressed
C = compress(t)
if not C:
    print(0)
    exit()
from collections import defaultdict
# Count occurrences of each character in the compressed T
char_counts = defaultdict(int)
for c in C:
    char_counts[c] += 1
# Mapping from character to its available count in S
alpha = 'abcdefghijklmnopqrstuvwxyz'
S = {alpha[i]: s_counts[i] for i in range(26)}
# Check if all characters in compressed T have sufficient count in S
valid = True
for c in char_counts:
    required = char_counts[c]
    if S[c] < required:
        valid = False
        break
if not valid:
    print(0)
    exit()
result = 1
# Calculate the product for each character's contribution
for c in char_counts:
    k = char_counts[c]
    available = S[c]
    rem = available - k
    if rem < 0:
        result = 0
        break
    base = rem // k
    r = rem % k
    # Compute (base + 2)^r * (base + 1)^(k - r) mod MOD
    part1 = pow(base + 2, r, MOD)
    part2 = pow(base + 1, k - r, MOD)
    total = (part1 * part2) % MOD
    result = (result * total) % MOD
print(result)
            
            
            
        