結果

問題 No.852 連続部分文字列
ユーザー uchiiiiuchiiii
提出日時 2020-07-26 16:23:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 3,153 ms
コード長 1,430 bytes
コンパイル時間 4,059 ms
コンパイル使用メモリ 230,032 KB
実行使用メモリ 9,892 KB
最終ジャッジ日時 2023-09-11 02:36:18
合計ジャッジ時間 7,985 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 40 ms
9,508 KB
testcase_34 AC 40 ms
9,504 KB
testcase_35 AC 40 ms
9,508 KB
testcase_36 AC 40 ms
9,752 KB
testcase_37 AC 40 ms
9,768 KB
testcase_38 AC 39 ms
9,504 KB
testcase_39 AC 39 ms
9,528 KB
testcase_40 AC 40 ms
9,768 KB
testcase_41 AC 40 ms
9,892 KB
testcase_42 AC 18 ms
9,796 KB
testcase_43 AC 34 ms
9,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
map<char, vector<int>> mp;


int main(){
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    string s; cin >> s;
    int n = s.size();
    
    auto f = [](ll n) { return (n+1)*n/2; };
    rep(i,26){
        mp[(char)(i+(int)'a')].emplace_back(-1);
    }
    rep(i,n) {
        mp[s[i]].emplace_back(i);
    }
    rep(i,26){
        mp[(char)(i+(int)'a')].emplace_back(n);
    }
    ll ans = f(n) * 26;
    rep(i, 26) {
        auto v = mp[(char)(i+(int)'a')];
        rep(i, v.size()-1) {
            int diff = v[i+1] - v[i];
            ans -= f(diff-1);
        }
    }

    ld res = ans;
    cout << res / f(n) << endl;
    return 0;
}
0