結果

問題 No.852 連続部分文字列
ユーザー kohei2019
提出日時 2022-05-04 12:26:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 287 ms / 3,153 ms
コード長 326 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,212 KB
実行使用メモリ 77,256 KB
最終ジャッジ日時 2024-07-03 14:50:08
合計ジャッジ時間 6,086 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
N = len(S)
alp = 'abcdefghijklmnopqrstuvwxyz'
ans = 0
allp = N*(N+1)//2
for i in range(26):
    rm = 0
    cnt = 0
    for j in range(N):
        if S[j] == alp[i]:
            rm += cnt*(cnt+1)//2
            cnt = 0
        else:
            cnt += 1
    rm += cnt*(cnt+1)//2
    ans += (allp-rm)/allp
print(ans)
0