結果

問題 No.852 連続部分文字列
ユーザー lloyz
提出日時 2022-08-23 00:55:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 346 ms / 3,153 ms
コード長 469 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 68,304 KB
最終ジャッジ日時 2024-10-10 07:10:35
合計ジャッジ時間 6,508 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

s = input()
n = len(s)
ans = 0.0
all_num = n * (n + 1) // 2
for i in range(26):
    res = 0
    cnt = 0
    for j in range(n):
        if s[j] == alph[i]:
            res += cnt * (cnt + 1) // 2
            cnt = 0
        else:
            cnt += 1
    res += cnt * (cnt + 1) // 2
    ans += (all_num - res) / all_num
print(ans)
0