結果
問題 | No.1171 Runs in Subsequences |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:11:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 79 ms / 2,000 ms |
コード長 | 877 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,532 KB |
実行使用メモリ | 88,616 KB |
最終ジャッジ日時 | 2025-03-20 21:13:20 |
合計ジャッジ時間 | 2,242 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
MOD = 10**9 + 7S = input().strip()N = len(S)# Precompute powers of 2 modulo MOD up to Npow2 = [1] * (N + 2)for i in range(1, N + 2):pow2[i] = (pow2[i-1] * 2) % MODfrom collections import defaultdictchar_positions = defaultdict(list)for idx, c in enumerate(S):char_positions[c].append(idx)sum_sub = 0for c in char_positions:positions = char_positions[c]sum_c = 0for j in range(len(positions)):pos = positions[j]if j == 0:sum_c = pow2[pos]continueexponent = N - pos - 1if exponent < 0:term = 0else:term = (sum_c * pow2[exponent]) % MODsum_sub = (sum_sub + term) % MODsum_c = (sum_c + pow2[pos]) % MOD# Compute N * pow2[N-1] mod MODpow_N_1 = pow2[N-1]total = (pow_N_1 * N) % MODans = (total - sum_sub) % MODprint(ans)