結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:38:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 129 ms / 3,153 ms |
| コード長 | 459 bytes |
| コンパイル時間 | 240 ms |
| コンパイル使用メモリ | 82,352 KB |
| 実行使用メモリ | 112,816 KB |
| 最終ジャッジ日時 | 2025-03-31 17:39:50 |
| 合計ジャッジ時間 | 5,143 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
s = input().strip()
n = len(s)
from collections import defaultdict
positions = defaultdict(list)
for idx, char in enumerate(s):
positions[char].append(idx)
total = 0
for ch in positions:
prev = -1
for i in positions[ch]:
left = i - prev
right = n - i
total += left * right
prev = i
num_substrings = n * (n + 1) // 2
average = total / num_substrings
# Print with 5 decimal places
print("{0:.5f}".format(average))
lam6er