結果

問題 No.852 連続部分文字列
ユーザー rlangevinrlangevin
提出日時 2023-03-12 13:07:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 737 ms / 3,153 ms
コード長 390 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 172,996 KB
最終ジャッジ日時 2023-10-18 10:36:04
合計ジャッジ時間 12,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,440 KB
testcase_01 AC 40 ms
53,440 KB
testcase_02 AC 38 ms
53,440 KB
testcase_03 AC 39 ms
53,440 KB
testcase_04 AC 39 ms
53,440 KB
testcase_05 AC 39 ms
53,440 KB
testcase_06 AC 39 ms
53,440 KB
testcase_07 AC 38 ms
53,440 KB
testcase_08 AC 38 ms
53,440 KB
testcase_09 AC 38 ms
53,440 KB
testcase_10 AC 38 ms
53,440 KB
testcase_11 AC 38 ms
53,440 KB
testcase_12 AC 38 ms
53,440 KB
testcase_13 AC 80 ms
76,400 KB
testcase_14 AC 74 ms
76,008 KB
testcase_15 AC 84 ms
77,044 KB
testcase_16 AC 77 ms
76,400 KB
testcase_17 AC 81 ms
76,796 KB
testcase_18 AC 84 ms
77,136 KB
testcase_19 AC 59 ms
68,336 KB
testcase_20 AC 75 ms
76,236 KB
testcase_21 AC 84 ms
77,188 KB
testcase_22 AC 75 ms
75,936 KB
testcase_23 AC 79 ms
76,648 KB
testcase_24 AC 75 ms
76,152 KB
testcase_25 AC 80 ms
76,592 KB
testcase_26 AC 85 ms
77,128 KB
testcase_27 AC 77 ms
76,448 KB
testcase_28 AC 81 ms
76,796 KB
testcase_29 AC 85 ms
77,188 KB
testcase_30 AC 72 ms
76,008 KB
testcase_31 AC 85 ms
77,252 KB
testcase_32 AC 85 ms
77,324 KB
testcase_33 AC 708 ms
171,684 KB
testcase_34 AC 704 ms
171,692 KB
testcase_35 AC 705 ms
170,800 KB
testcase_36 AC 705 ms
171,604 KB
testcase_37 AC 699 ms
171,688 KB
testcase_38 AC 699 ms
171,660 KB
testcase_39 AC 709 ms
172,196 KB
testcase_40 AC 698 ms
171,744 KB
testcase_41 AC 704 ms
171,796 KB
testcase_42 AC 657 ms
172,996 KB
testcase_43 AC 737 ms
171,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import *

S = list(input())
N = len(S)
D = [[0, N+1] for i in range(26)]
for i in range(N):
    D[ord(S[i]) - ord("a")].append(i + 1)

for i in range(26):
    D[i].sort()    

ans = 0
for i in range(N):
    n = ord(S[i]) - ord("a")
    right = bisect_right(D[n], i+1)
    left = bisect_left(D[n], i+1)-1
    ans += (N+1 - i-1)*(i+1 - D[n][left])
    
print(ans/(N * (N + 1)//2))
0