結果

問題 No.852 連続部分文字列
ユーザー kappybar
提出日時 2020-04-09 12:11:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 3,153 ms
コード長 653 bytes
コンパイル時間 3,359 ms
コンパイル使用メモリ 172,428 KB
実行使用メモリ 16,148 KB
最終ジャッジ日時 2024-07-23 11:43:00
合計ジャッジ時間 4,819 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
using pp = pair<bool,bool>;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    string s;
    cin >> s;
    ll n = s.size();
    ll res = n*(n+1)*(n+2)/6;
    vector<vector<ll>> mp(26,vector<ll>());
    rep(i,n){
        mp[s[i]-'a'].push_back(i);
    }
    
    rep(i,26){
        int sz = mp[i].size();
        for(int j = 0;j<=sz-2;j++){
            res -= (mp[i][j]+1) * (n - mp[i][j+1]);
        }
    }
    
    double ans = (double)(res)/(double)(n*(n+1)/2);
    printf("%.7f",ans);
    return 0;
}
0