結果

問題 No.852 連続部分文字列
ユーザー hipopohipopo
提出日時 2020-04-13 19:44:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,360 bytes
コンパイル時間 1,344 ms
コンパイル使用メモリ 142,608 KB
実行使用メモリ 13,068 KB
最終ジャッジ日時 2023-10-25 23:20:42
合計ジャッジ時間 5,424 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 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,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 5 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 5 ms
4,348 KB
testcase_32 AC 5 ms
4,348 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

template<typename T>
vector<pair<T, int>> rle(const vector<T> &v) {
    vector<pair<T, int>> res;
    for (int i = 0; i < (int)v.size();) {
        int j = i;
        while (j < (int)v.size() && v.at(i) == v.at(j)) j++;
        res.emplace_back(v.at(i), j - i);
        i = j;
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll all = (n + 1) * n / 2;
    
    ll cnt = 0;
    for (char c = 'a'; c <= 'z'; c++) {
        vector<char> t(n);
        bool ok = false;
        rep(i, n) {
            if (s[i] != c) t[i] = '?';
            else {
                t[i] = c;
                ok = true;
            }
        }
        if (!ok) continue;
        
        auto res = rle(t);
        ll cnt_none = 0;
        for (auto p: res) if (p.first != c) cnt_none += (p.second + 1) * p.second / 2;
        cnt += all - cnt_none;
    }
    
    double ans = double(cnt) / all;
    printf("%.10lf\n", ans);
}
0