結果

問題 No.852 連続部分文字列
ユーザー leaf_1415leaf_1415
提出日時 2019-07-26 21:42:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 3,153 ms
コード長 668 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 65,184 KB
実行使用メモリ 15,940 KB
最終ジャッジ日時 2023-09-15 00:54:47
合計ジャッジ時間 2,840 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 33 ms
14,796 KB
testcase_34 AC 34 ms
15,316 KB
testcase_35 AC 34 ms
15,048 KB
testcase_36 AC 34 ms
15,124 KB
testcase_37 AC 34 ms
14,848 KB
testcase_38 AC 34 ms
15,084 KB
testcase_39 AC 34 ms
15,316 KB
testcase_40 AC 35 ms
15,224 KB
testcase_41 AC 35 ms
15,328 KB
testcase_42 AC 35 ms
15,940 KB
testcase_43 AC 34 ms
14,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#define llint long long

using namespace std;

string s;
vector<llint> vec[26];

int main(void)
{
	cin >> s;
	llint n = s.size();
	s = "#" + s;
	for(int i = 0; i < 26; i++) vec[i].push_back(0);
	for(int i = 1; i <= n; i++){
		vec[s[i]-'a'].push_back(i);
	}
	for(int i = 0; i < 26; i++) vec[i].push_back(n+1);
	
	llint ans = 0;
	for(int i = 0; i < 26; i++){
		ans += n*(n+1)/2;
		for(int j = 1; j < vec[i].size(); j++){
			llint len = vec[i][j]-vec[i][j-1]-1;
			ans -= len*(len+1)/2;
		}
	}
	printf("%.11f\n", (double)ans / (n*(n+1)/2));
	
	return 0;
}
0