結果

問題 No.852 連続部分文字列
ユーザー ゆにぽけゆにぽけ
提出日時 2023-11-01 13:08:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 3,153 ms
コード長 1,038 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 130,892 KB
実行使用メモリ 10,036 KB
最終ジャッジ日時 2023-11-01 13:08:46
合計ジャッジ時間 4,379 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
using namespace std;
string S;
vector<int> idx[26];
void solve()
{
	cin >> S;
	int N = (int)S.size();
	for(int i = 0;i < 26;i++) idx[i].push_back(-1);
	for(int i = 0;i < N;i++) idx[S[i]-'a'].push_back(i);
	for(int i = 0;i < 26;i++) idx[i].push_back(N);
	long long num = 0,den = (long long)N*(N+1)/2;
	for(int i = 0;i < 26;i++)
	{
		long long cur = (long long)N*(N+1)/2;
		for(int j = 0;j+1 < (int)idx[i].size();j++)
		{
			int d = idx[i][j+1]-idx[i][j]-1;
			cur -= (long long)d*(d+1)/2;
		}
		num += cur;
	}
	cout << fixed << setprecision(20) << (long double)num/den << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) solve();
}

0