結果
| 問題 | No.603 hel__world (2) | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-04-16 00:04:43 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,149 bytes | 
| コンパイル時間 | 199 ms | 
| コンパイル使用メモリ | 81,896 KB | 
| 実行使用メモリ | 163,012 KB | 
| 最終ジャッジ日時 | 2025-04-16 00:06:47 | 
| 合計ジャッジ時間 | 3,598 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 WA * 20 | 
ソースコード
MOD = 10**6 + 3
def compress(s):
    if not s:
        return []
    res = [s[0]]
    for c in s[1:]:
        if c != res[-1]:
            res.append(c)
    return res
def main():
    import sys
    s_counts = list(map(int, sys.stdin.readline().split()))
    t = sys.stdin.readline().strip()
    
    t_compress = compress(t)
    from collections import defaultdict
    cnt = defaultdict(int)
    for c in t_compress:
        cnt[c] += 1
    
    # Check if all characters in cnt have sufficient S_alpha
    for c in cnt:
        idx = ord(c) - ord('a')
        if s_counts[idx] < cnt[c]:
            print(0)
            return
    
    result = 1
    for c in cnt:
        idx = ord(c) - ord('a')
        sc = s_counts[idx]
        k = cnt[c]
        if k == 0:
            continue
        
        total = sc - k
        if total < 0:
            print(0)
            return
        
        q, r = divmod(total, k)
        part1 = pow(q + 2, r, MOD)
        part2 = pow(q + 1, k - r, MOD)
        contribution = (part1 * part2) % MOD
        result = (result * contribution) % MOD
    
    print(result)
if __name__ == '__main__':
    main()
            
            
            
        