結果

問題 No.852 連続部分文字列
ユーザー 1119_29161119_2916
提出日時 2019-08-01 17:46:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 456 ms / 3,153 ms
コード長 1,669 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 171,872 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 17:40:29
合計ジャッジ時間 8,095 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 5 ms
4,384 KB
testcase_15 AC 15 ms
4,376 KB
testcase_16 AC 10 ms
4,376 KB
testcase_17 AC 13 ms
4,380 KB
testcase_18 AC 16 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 16 ms
4,380 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 12 ms
4,380 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 11 ms
4,380 KB
testcase_26 AC 16 ms
4,376 KB
testcase_27 AC 10 ms
4,380 KB
testcase_28 AC 13 ms
4,380 KB
testcase_29 AC 16 ms
4,380 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 17 ms
4,376 KB
testcase_32 AC 17 ms
4,376 KB
testcase_33 AC 452 ms
4,376 KB
testcase_34 AC 453 ms
4,376 KB
testcase_35 AC 453 ms
4,380 KB
testcase_36 AC 452 ms
4,376 KB
testcase_37 AC 454 ms
4,376 KB
testcase_38 AC 456 ms
4,380 KB
testcase_39 AC 453 ms
4,380 KB
testcase_40 AC 453 ms
4,376 KB
testcase_41 AC 455 ms
4,376 KB
testcase_42 AC 241 ms
4,380 KB
testcase_43 AC 268 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    string st;
    cin >> st;

    int n = st.size();
    
    vi pos(26, 0);
    vi cnt(27, 0);
    rep(i, n) {
        pos[st[i] - 'a'] = i+1;
        /*
        rep(j, pos.size()) {
            cout << pos[j] << " ";
        }
        cout << endl;
        */
        vi sorted = pos;
        sorted.emplace_back(0);
        sort(all(sorted));
        reverse(all(sorted));
        Rep(j, sorted.size()) {
            cnt[j] += sorted[j-1] - sorted[j];
        }
    }

    int sum = 0;
    rep(i, cnt.size()) {
        sum += cnt[i] * i;
        //std::cout << cnt[i] << std::endl;
    }

    cout << Decimal << (double)sum / (n * (n+1) / 2.0) << endl;

    return 0;
}
0