結果

問題 No.852 連続部分文字列
ユーザー ok
提出日時 2019-09-03 13:34:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 3,153 ms
コード長 789 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 96,156 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 22:32:57
合計ジャッジ時間 3,364 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

 #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

const int NUM = 26;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	long double ans = 0;
	vector<int> used;
	int dp = 0, sum = 0;
	string s;
	
	cin>>s;
	
	used.resize(NUM,-1);
	
	for(int i = 0; i < s.size(); i++){
		dp += i - used[s[i] - 'a'];
		sum += dp;
		used[s[i] - 'a'] = i;
	}
	// cout<<sum<<endl;
	cout<<((double)sum/((int)s.size()*(s.size()+1)/2))<<endl;
	
	return 0;
} 
0