結果

問題 No.852 連続部分文字列
ユーザー mencotton
提出日時 2019-07-26 22:05:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 53 ms / 3,153 ms
コード長 487 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 74,860 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-02 07:21:07
合計ジャッジ時間 2,632 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;

int main() {
    string s;
    cin >> s;

    vector<long double> last(26);
    long double ret = 0;
    for (double i = 1; i <= s.size(); i++) {
        last[s[i - 1] - 'a'] = i;
        for (int j = 0; j < 26; j++) {
            ret += last[j];
        }
    }

    long long l = s.size();
    l = l * (l + 1) / 2;
    cout << fixed << setprecision(18) <<ret / l << endl;
    return 0;
}
0