結果

問題 No.852 連続部分文字列
ユーザー CuriousFairy315
提出日時 2019-03-20 15:12:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 481 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 82,376 KB
最終ジャッジ日時 2025-01-06 23:37:38
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 11 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdint>
#include<iomanip>
#include<set>
using namespace std; // 575

int main() {
	string S;
	cin >> S;
	set<int> alpha[26];
	int64_t sum = 0;
	for (int i = 0;i < 26;++ i) alpha[i].insert(S.size());
	for (int i = 0;i < S.size();++ i) alpha[S[i] - 'a'].insert(i);
	for (int i = 0;i < S.size();++ i) sum += (*alpha[S[i] - 'a'].upper_bound(i) - i) * (i + 1);
	cout << setprecision(3) << fixed << sum * 2.0 / S.size() / (S.size() + 1) << endl;
	return 0;
}
0