結果

問題 No.852 連続部分文字列
ユーザー manjuuu_onsen
提出日時 2020-09-10 17:32:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 609 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 173,956 KB
実行使用メモリ 16,144 KB
最終ジャッジ日時 2024-12-23 14:11:04
合計ジャッジ時間 4,152 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main()
{
	string s; ll n;
	cin >> s; n = s.size();
	vector<vector<ll>> pos(26);
	for(auto &i: pos)i.push_back(-1);

	for(int i = 0; i < n; i++) {
		pos[s[i] - 'a'].push_back(i);
	}
	for(auto &i: pos)i.push_back(n);
	ll unit = n * (n + 1) / 2;

	ll sum = 0;
	for(int i = 0; i < 26; i++) {
		ll cur = unit;
		int m = pos[i].size();
		for(int j = 0; j < m - 1; j++) {
			int num = pos[i][j+1] - pos[i][j];
			cur -= num * (num - 1) / 2;
		}
		sum += cur;
	}
	cout << fixed <<setprecision(12) << (double)sum / ((n) * (n+1) / 2) << endl; 
}
0