結果

問題 No.852 連続部分文字列
ユーザー ntuda
提出日時 2025-01-12 20:42:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 180 ms / 3,153 ms
コード長 270 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,696 KB
最終ジャッジ日時 2025-01-12 20:42:49
合計ジャッジ時間 5,119 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

dic = defaultdict(int)
S = input()
N = len(S)
ans = 0
tmp1 = 0
for i, s in enumerate(S):
    x = 0
    if s in dic:
        x = dic[s]
    tmp1 += (i - x + 1)
    ans += tmp1
    dic[s] = i + 1
ans *= 2
ans /= N * (N + 1)
print(ans)
0