結果

問題 No.852 連続部分文字列
ユーザー fine
提出日時 2019-07-26 21:44:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 726 bytes
コンパイル時間 1,471 ms
コンパイル使用メモリ 166,932 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-07-02 06:52:26
合計ジャッジ時間 3,313 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll calc(string& s, char c) {
    ll n = s.size();
    ll res = n * (n + 1) / 2;

    ll cur = 0;
    for (ll i = 0; i < n; i++) {
        if (s[i] == c) {
            ll d = i - cur;
            res -= d * (d + 1) / 2;
            cur = i + 1;
        }
    }

    ll d = n - cur;
    res -= d * (d + 1) / 2;
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();

    ll val1 = 0;
    for (int i = 0; i < 26; i++) {
        val1 += calc(s, 'a' + i);
    }

    ll val2 = n * (n + 1) / 2;
    cout << fixed << setprecision(15) << (long double)val1 / val2 << endl;
    return 0;
}
0