結果

問題 No.852 連続部分文字列
ユーザー NoneNone
提出日時 2021-03-03 17:01:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 157 ms / 3,153 ms
コード長 1,086 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 116,736 KB
最終ジャッジ日時 2024-04-14 09:08:08
合計ジャッジ時間 6,083 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
54,132 KB
testcase_01 AC 51 ms
54,440 KB
testcase_02 AC 52 ms
54,672 KB
testcase_03 AC 53 ms
54,056 KB
testcase_04 AC 57 ms
54,072 KB
testcase_05 AC 51 ms
54,664 KB
testcase_06 AC 51 ms
55,008 KB
testcase_07 AC 45 ms
54,512 KB
testcase_08 AC 43 ms
53,792 KB
testcase_09 AC 44 ms
54,676 KB
testcase_10 AC 42 ms
54,540 KB
testcase_11 AC 42 ms
54,660 KB
testcase_12 AC 42 ms
53,884 KB
testcase_13 AC 52 ms
65,276 KB
testcase_14 AC 51 ms
63,452 KB
testcase_15 AC 54 ms
67,312 KB
testcase_16 AC 52 ms
66,216 KB
testcase_17 AC 53 ms
65,964 KB
testcase_18 AC 54 ms
67,548 KB
testcase_19 AC 50 ms
62,504 KB
testcase_20 AC 51 ms
64,448 KB
testcase_21 AC 57 ms
67,496 KB
testcase_22 AC 51 ms
63,964 KB
testcase_23 AC 54 ms
65,964 KB
testcase_24 AC 54 ms
65,260 KB
testcase_25 AC 53 ms
65,952 KB
testcase_26 AC 54 ms
67,564 KB
testcase_27 AC 53 ms
66,200 KB
testcase_28 AC 53 ms
65,956 KB
testcase_29 AC 55 ms
68,744 KB
testcase_30 AC 52 ms
63,692 KB
testcase_31 AC 54 ms
67,916 KB
testcase_32 AC 55 ms
68,440 KB
testcase_33 AC 153 ms
115,876 KB
testcase_34 AC 150 ms
116,736 KB
testcase_35 AC 157 ms
116,000 KB
testcase_36 AC 156 ms
116,408 KB
testcase_37 AC 149 ms
116,284 KB
testcase_38 AC 151 ms
115,964 KB
testcase_39 AC 155 ms
116,176 KB
testcase_40 AC 151 ms
116,124 KB
testcase_41 AC 153 ms
115,868 KB
testcase_42 AC 152 ms
116,280 KB
testcase_43 AC 152 ms
116,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def SameRange(A):
    N=len(A)
    pre_same=[-1]*N
    next_same=[N]*N
    last_pos = defaultdict(lambda: -1)
    for i, a in enumerate(A):
        j = last_pos[a]
        if j==-1:
            last_pos[a] = i
        else:
            next_same[j] = i
            pre_same[i] = j
            last_pos[a] = i
    return pre_same, next_same

def count_pair(i,l,r):
    """
    部分列 [l,r] の中で、i を含む部分列の個数
    """
    return (i-l+1)*(r-i+1)


#######################################################################################
def example():
    global input
    example = iter(
        """
7
1 1 3 3 3 2 2
        """
            .strip().split("\n"))
    input = lambda: next(example)

#######################################################################################
import sys
input = sys.stdin.readline
from collections import defaultdict

# example()

A=[]
for s in input().rstrip():
    A.append(ord(s)-ord("a"))
N=len(A)
cnt=0
L,R = SameRange(A)
for i in range(N):
    l,r=L[i],R[i]
    cnt+=count_pair(i,l+1,N-1)

T=N*(N+1)//2
print(cnt/T)
0