結果

問題 No.852 連続部分文字列
コンテスト
ユーザー roaris
提出日時 2019-07-27 01:51:30
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 345 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 368 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 95,992 KB
最終ジャッジ日時 2026-03-23 18:20:51
合計ジャッジ時間 13,874 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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