結果

問題 No.852 連続部分文字列
ユーザー kappybarkappybar
提出日時 2020-04-09 13:10:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 3,153 ms
コード長 623 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 167,680 KB
実行使用メモリ 12,116 KB
最終ジャッジ日時 2023-10-11 05:12:11
合計ジャッジ時間 5,402 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,356 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 26 ms
12,052 KB
testcase_34 AC 26 ms
12,116 KB
testcase_35 AC 26 ms
11,976 KB
testcase_36 AC 26 ms
12,016 KB
testcase_37 AC 26 ms
11,988 KB
testcase_38 AC 25 ms
12,052 KB
testcase_39 AC 25 ms
11,972 KB
testcase_40 AC 25 ms
11,984 KB
testcase_41 AC 25 ms
12,096 KB
testcase_42 AC 25 ms
12,044 KB
testcase_43 AC 25 ms
12,048 KB
権限があれば一括ダウンロードができます

ソースコード

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> ;
const int INF = 1e9;
const int MOD = 1000000007;

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