結果

問題 No.852 連続部分文字列
ユーザー roarisroaris
提出日時 2019-07-28 14:08:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 927 ms / 3,153 ms
コード長 335 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 10,664 KB
実行使用メモリ 90,848 KB
最終ジャッジ日時 2023-09-15 11:31:21
合計ジャッジ時間 13,671 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,304 KB
testcase_01 AC 18 ms
8,396 KB
testcase_02 AC 18 ms
8,464 KB
testcase_03 AC 18 ms
8,372 KB
testcase_04 AC 18 ms
8,448 KB
testcase_05 AC 18 ms
8,348 KB
testcase_06 AC 18 ms
8,352 KB
testcase_07 AC 18 ms
8,360 KB
testcase_08 AC 18 ms
8,272 KB
testcase_09 AC 18 ms
8,412 KB
testcase_10 AC 19 ms
8,444 KB
testcase_11 AC 18 ms
8,320 KB
testcase_12 AC 18 ms
8,452 KB
testcase_13 AC 32 ms
9,648 KB
testcase_14 AC 24 ms
9,072 KB
testcase_15 AC 40 ms
10,636 KB
testcase_16 AC 30 ms
9,752 KB
testcase_17 AC 37 ms
10,272 KB
testcase_18 AC 42 ms
10,652 KB
testcase_19 AC 20 ms
8,460 KB
testcase_20 AC 29 ms
9,408 KB
testcase_21 AC 43 ms
10,684 KB
testcase_22 AC 26 ms
9,084 KB
testcase_23 AC 34 ms
10,000 KB
testcase_24 AC 28 ms
9,316 KB
testcase_25 AC 34 ms
9,952 KB
testcase_26 AC 43 ms
10,680 KB
testcase_27 AC 32 ms
9,724 KB
testcase_28 AC 37 ms
10,304 KB
testcase_29 AC 43 ms
10,708 KB
testcase_30 AC 23 ms
8,800 KB
testcase_31 AC 45 ms
11,076 KB
testcase_32 AC 45 ms
10,924 KB
testcase_33 AC 905 ms
90,628 KB
testcase_34 AC 890 ms
90,592 KB
testcase_35 AC 892 ms
90,228 KB
testcase_36 AC 892 ms
90,208 KB
testcase_37 AC 883 ms
90,232 KB
testcase_38 AC 886 ms
90,560 KB
testcase_39 AC 894 ms
90,848 KB
testcase_40 AC 871 ms
90,540 KB
testcase_41 AC 889 ms
90,824 KB
testcase_42 AC 927 ms
89,948 KB
testcase_43 AC 873 ms
89,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

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

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

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