結果
問題 |
No.295 hel__world
|
ユーザー |
![]() |
提出日時 | 2025-06-12 12:54:04 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,770 bytes |
コンパイル時間 | 238 ms |
コンパイル使用メモリ | 82,412 KB |
実行使用メモリ | 158,768 KB |
最終ジャッジ日時 | 2025-06-12 12:57:42 |
合計ジャッジ時間 | 4,936 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 WA * 19 |
ソースコード
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 from collections import defaultdict # Read S_alpha s_alpha_line = sys.stdin.readline().strip().split() s_alpha = {chr(ord('a') + i): int(s_alpha_line[i]) for i in range(26)} # Read T t = sys.stdin.readline().strip() if not t: print(0) return # Compress T t_compressed = compress(t) if not t_compressed: print(0) return # Check if any character in T_compressed has S_alpha[c] == 0 for c in t_compressed: if s_alpha[c] == 0: print(0) return # Count frequency of each character in T_compressed freq = defaultdict(int) for c in t_compressed: freq[c] += 1 # Check if for each c in freq, S_alpha[c] >= freq[c] for c in freq: if s_alpha[c] < freq[c]: print(0) return hel_limit = 2 ** 62 product = 1 for c in freq: m_c = freq[c] sum_available = s_alpha[c] - m_c q, r = divmod(sum_available, m_c) # Compute term = (q+2)^r * (q+1)^(m_c - r) term = 1 # Compute (q+2)^r if r > 0: term *= pow(q + 2, r) # Compute (q+1)^(m_c - r) if m_c - r > 0: term *= pow(q + 1, m_c - r) # Multiply to product and check overflow if product > hel_limit // term: print("hel") return product *= term if product >= hel_limit: print("hel") return print(product) if __name__ == "__main__": main()