結果

問題 No.852 連続部分文字列
ユーザー SSRSSSRS
提出日時 2020-11-20 17:50:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 3,153 ms
コード長 706 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 77,840 KB
実行使用メモリ 9,888 KB
最終ジャッジ日時 2023-09-30 18:34:47
合計ジャッジ時間 2,882 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 28 ms
9,824 KB
testcase_34 AC 28 ms
9,860 KB
testcase_35 AC 29 ms
9,540 KB
testcase_36 AC 28 ms
9,520 KB
testcase_37 AC 28 ms
9,888 KB
testcase_38 AC 28 ms
9,528 KB
testcase_39 AC 29 ms
9,640 KB
testcase_40 AC 29 ms
9,844 KB
testcase_41 AC 28 ms
9,516 KB
testcase_42 AC 28 ms
9,888 KB
testcase_43 AC 28 ms
9,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
int main(){
	cout << fixed << setprecision(10);
	string S;
	cin >> S;
	int N = S.size();
	vector<vector<int>> p(26);
	for (int i = 0; i < 26; i++){
		p[i].push_back(-1);
	}
	for (int i = 0; i < N; i++){
		p[S[i] - 'a'].push_back(i);
	}
	for (int i = 0; i < 26; i++){
		p[i].push_back(N);
	}
	double ans = 0;
	for (int i = 0; i < 26; i++){
		long long sum = (long long) N * (N + 1) / 2;
		int M = p[i].size() - 1;
		for (int j = 0; j < M; j++){
			sum -= (long long) (p[i][j + 1] - p[i][j] - 1) * (p[i][j + 1] - p[i][j]) / 2;
		}
		ans += (double) sum / ((long long) N * (N + 1) / 2);
	}
	cout << ans << endl;
}
0