結果

問題 No.852 連続部分文字列
ユーザー Chihaya_chanChihaya_chan
提出日時 2020-06-14 12:33:11
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 1,118 ms / 3,153 ms
コード長 407 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 10,704 KB
実行使用メモリ 58,312 KB
最終ジャッジ日時 2023-09-09 11:53:15
合計ジャッジ時間 15,763 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,816 KB
testcase_01 AC 16 ms
7,812 KB
testcase_02 AC 15 ms
7,808 KB
testcase_03 AC 16 ms
7,920 KB
testcase_04 AC 15 ms
7,704 KB
testcase_05 AC 16 ms
7,748 KB
testcase_06 AC 15 ms
7,816 KB
testcase_07 AC 15 ms
7,888 KB
testcase_08 AC 16 ms
7,908 KB
testcase_09 AC 16 ms
7,804 KB
testcase_10 AC 17 ms
7,704 KB
testcase_11 AC 15 ms
7,712 KB
testcase_12 AC 15 ms
7,740 KB
testcase_13 AC 31 ms
8,780 KB
testcase_14 AC 23 ms
8,360 KB
testcase_15 AC 41 ms
9,372 KB
testcase_16 AC 31 ms
8,704 KB
testcase_17 AC 36 ms
9,028 KB
testcase_18 AC 42 ms
9,392 KB
testcase_19 AC 18 ms
7,812 KB
testcase_20 AC 26 ms
8,628 KB
testcase_21 AC 43 ms
9,596 KB
testcase_22 AC 24 ms
8,432 KB
testcase_23 AC 35 ms
9,008 KB
testcase_24 AC 26 ms
8,600 KB
testcase_25 AC 34 ms
8,924 KB
testcase_26 AC 44 ms
9,300 KB
testcase_27 AC 31 ms
8,968 KB
testcase_28 AC 38 ms
9,052 KB
testcase_29 AC 44 ms
9,336 KB
testcase_30 AC 20 ms
8,072 KB
testcase_31 AC 45 ms
9,680 KB
testcase_32 AC 46 ms
9,552 KB
testcase_33 AC 1,114 ms
57,496 KB
testcase_34 AC 1,067 ms
56,984 KB
testcase_35 AC 1,044 ms
58,040 KB
testcase_36 AC 1,036 ms
58,020 KB
testcase_37 AC 1,097 ms
58,104 KB
testcase_38 AC 1,118 ms
58,312 KB
testcase_39 AC 1,073 ms
57,680 KB
testcase_40 AC 1,093 ms
57,840 KB
testcase_41 AC 1,100 ms
57,592 KB
testcase_42 AC 1,099 ms
57,064 KB
testcase_43 AC 1,008 ms
57,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = list(input())
N = len(S)
alpha = "abcdefghijklmnopqrstuvwxyz"
d = {alpha[i]: [0] for i in range(26)}
for i in range(N):
    d[S[i]].append(i+1)
for i in range(26):
    d[alpha[i]].append(N+1)
ans = 0
down = N*(N+1)//2
for i in range(26):
    P = N*(N+1)//2
    for j in range(len(d[alpha[i]])-1):
        x, y = d[alpha[i]][j], d[alpha[i]][j+1]
        P -= (y-x)*(y-x-1)//2
    ans += P/down
print(ans)
0