結果

問題 No.852 連続部分文字列
ユーザー SAAD AHMAD
提出日時 2022-07-12 05:31:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 3,153 ms
コード長 529 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 168,464 KB
実行使用メモリ 12,520 KB
最終ジャッジ日時 2024-06-23 00:52:38
合計ジャッジ時間 2,833 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

 
signed main(){
    cout << setprecision(12) ;
    ios::sync_with_stdio(false);
	cin.tie(0);

    string s;
    cin>>s;
    int n=s.size();
    ll dp[n+1]={}; //iを右端にしたときの文字列の種類数の総和
    vector<int> pre(26,-1);
    double ans=0;
    for(int i=0;i<n;i++){
        dp[i + 1] = dp[i] + i-pre[s[i]-'a'];
        pre[s[i]-'a'] = i;
        ans += dp[i+1];
    }
    ans /= (double)n*(n+1)/2.0;
    cout<<ans<<endl;
    


    
}
0