結果

問題 No.852 連続部分文字列
ユーザー brthyyjp
提出日時 2020-08-05 00:31:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 407 ms / 3,153 ms
コード長 372 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 133,248 KB
最終ジャッジ日時 2024-09-15 01:08:48
合計ジャッジ時間 7,199 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

s = str(input())

n = len(s)
ans = 0
for i in range(26):
    c = chr(i+ord('a'))
    X = []
    cnt = 0
    for j in range(n):
        if s[j] != c:
            cnt += 1
        else:
            X.append(cnt)
            cnt = 0
    else:
        X.append(cnt)
    temp = n*(n+1)//2
    for x in X:
        temp -= x*(x+1)//2
    ans += temp
ans /= n*(n+1)//2
print(ans)
0