結果
問題 |
No.603 hel__world (2)
|
ユーザー |
![]() |
提出日時 | 2025-06-12 14:47:15 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,353 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 81,956 KB |
実行使用メモリ | 163,724 KB |
最終ジャッジ日時 | 2025-06-12 14:49:50 |
合計ジャッジ時間 | 3,854 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)