結果

問題 No.852 連続部分文字列
ユーザー roaris
提出日時 2019-07-27 01:51:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 345 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 93,160 KB
最終ジャッジ日時 2024-07-02 10:25:36
合計ジャッジ時間 12,711 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

S = input()
N = len(S)
dp = [0] * N
dp[0] = 1
appear_dict = defaultdict(list)

for i in range(1, N):
    if len(appear_dict[S[i]]) == 0:
        dp[i] = dp[i-1] + i + 1
    else:
        dp[i] = dp[i-1] + i - appear_dict[S[i]][-1]
    
    appear_dict[S[i]].append(i)

ans = sum(dp) / (N*(N+1)/2)
print(ans)
0