結果

問題 No.852 連続部分文字列
ユーザー otoshigootoshigo
提出日時 2023-02-24 14:58:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 3,153 ms
コード長 991 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 15,804 KB
最終ジャッジ日時 2023-10-10 00:07:10
合計ジャッジ時間 4,255 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 1 ms
4,372 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 17 ms
14,584 KB
testcase_34 AC 18 ms
14,220 KB
testcase_35 AC 18 ms
14,316 KB
testcase_36 AC 17 ms
14,076 KB
testcase_37 AC 18 ms
14,444 KB
testcase_38 AC 17 ms
13,912 KB
testcase_39 AC 18 ms
13,992 KB
testcase_40 AC 18 ms
14,172 KB
testcase_41 AC 18 ms
14,508 KB
testcase_42 AC 18 ms
15,804 KB
testcase_43 AC 18 ms
14,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(10);
    string s;
    cin>>s;
    ll n=s.size();
    vector<vector<ll>>C(26);
    rep(i,n){
        C[s[i]-'a'].push_back(i);
    }
    double ans=0;
    rep(i,26){
        if(C[i].empty())continue;
        ll k=n*(n+1)/2-C[i].front()*(C[i].front()+1)/2-(n-1-C[i].back())*(n-C[i].back())/2;
        rep(j,(int)C[i].size()-1){
            ll l=C[i][j+1]-C[i][j];
            k-=(l)*(l-1)/2;
        }
        ans+=k/(double)(n*(n+1)/2);
    }
    cout<<ans<<"\n";
}
0