結果

問題 No.852 連続部分文字列
ユーザー kekurekekure
提出日時 2019-10-15 13:04:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 251 ms / 3,153 ms
コード長 633 bytes
コンパイル時間 427 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 118,352 KB
最終ジャッジ日時 2023-08-27 16:47:53
合計ジャッジ時間 7,779 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,116 KB
testcase_01 AC 69 ms
71,352 KB
testcase_02 AC 65 ms
71,136 KB
testcase_03 AC 67 ms
71,352 KB
testcase_04 AC 65 ms
71,120 KB
testcase_05 AC 65 ms
71,232 KB
testcase_06 AC 65 ms
71,348 KB
testcase_07 AC 65 ms
71,364 KB
testcase_08 AC 64 ms
71,216 KB
testcase_09 AC 66 ms
71,420 KB
testcase_10 AC 63 ms
71,104 KB
testcase_11 AC 67 ms
71,244 KB
testcase_12 AC 65 ms
71,516 KB
testcase_13 AC 87 ms
76,308 KB
testcase_14 AC 74 ms
76,088 KB
testcase_15 AC 77 ms
76,452 KB
testcase_16 AC 76 ms
76,404 KB
testcase_17 AC 76 ms
76,408 KB
testcase_18 AC 75 ms
76,324 KB
testcase_19 AC 75 ms
76,268 KB
testcase_20 AC 80 ms
76,328 KB
testcase_21 AC 81 ms
76,368 KB
testcase_22 AC 73 ms
76,368 KB
testcase_23 AC 76 ms
76,288 KB
testcase_24 AC 73 ms
76,428 KB
testcase_25 AC 76 ms
76,472 KB
testcase_26 AC 79 ms
76,320 KB
testcase_27 AC 75 ms
76,572 KB
testcase_28 AC 77 ms
76,532 KB
testcase_29 AC 80 ms
76,320 KB
testcase_30 AC 76 ms
76,092 KB
testcase_31 AC 78 ms
76,336 KB
testcase_32 AC 80 ms
76,384 KB
testcase_33 AC 241 ms
117,068 KB
testcase_34 AC 240 ms
117,116 KB
testcase_35 AC 241 ms
116,528 KB
testcase_36 AC 238 ms
116,872 KB
testcase_37 AC 246 ms
116,804 KB
testcase_38 AC 251 ms
117,328 KB
testcase_39 AC 240 ms
117,452 KB
testcase_40 AC 250 ms
117,140 KB
testcase_41 AC 237 ms
117,028 KB
testcase_42 AC 245 ms
118,352 KB
testcase_43 AC 229 ms
111,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
l = len(s)
C = [0] * l #1~l文字までの文字の種類の数
dic ={}
dic_a = {}
k = 0
for i in range(l):
    c = s[i]
    if c in dic:
        dic[c][0] += 1
    else:
        dic[c] = [1, [], 1]
        k += 1
    dic[c][1].append(i)
    C[i] = k
w = sum(C)
sum_w = w

for i in range(1, l): #i番目から始める部分文字列
    b = s[i - 1] #手前の文字
    n = l - i

    char_num, char_list, counter = dic[b]

    if counter < char_num:
        n = char_list[counter] - char_list[counter - 1] - 1
        dic[b][2] += 1

    w = w - n - 1
    sum_w += w

n = l * (l + 1) / 2
print(sum_w / n)











0