結果

問題 No.852 連続部分文字列
ユーザー le_panda_noirle_panda_noir
提出日時 2020-05-31 12:23:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,778 ms / 3,153 ms
コード長 966 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 104,216 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2023-08-10 20:47:10
合計ジャッジ時間 22,829 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 26 ms
4,380 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 45 ms
4,380 KB
testcase_16 AC 26 ms
4,380 KB
testcase_17 AC 37 ms
4,376 KB
testcase_18 AC 48 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 22 ms
4,376 KB
testcase_21 AC 50 ms
4,380 KB
testcase_22 AC 16 ms
4,380 KB
testcase_23 AC 32 ms
4,376 KB
testcase_24 AC 18 ms
4,380 KB
testcase_25 AC 31 ms
4,380 KB
testcase_26 AC 50 ms
4,376 KB
testcase_27 AC 28 ms
4,376 KB
testcase_28 AC 37 ms
4,380 KB
testcase_29 AC 48 ms
4,380 KB
testcase_30 AC 10 ms
4,376 KB
testcase_31 AC 53 ms
4,376 KB
testcase_32 AC 52 ms
4,376 KB
testcase_33 AC 1,754 ms
9,648 KB
testcase_34 AC 1,738 ms
9,944 KB
testcase_35 AC 1,726 ms
9,592 KB
testcase_36 AC 1,771 ms
9,272 KB
testcase_37 AC 1,730 ms
9,680 KB
testcase_38 AC 1,747 ms
9,536 KB
testcase_39 AC 1,778 ms
9,944 KB
testcase_40 AC 1,756 ms
9,808 KB
testcase_41 AC 1,757 ms
9,540 KB
testcase_42 AC 1,295 ms
10,112 KB
testcase_43 AC 1,233 ms
9,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
template<class T>using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;

int main() {
  string S; cin >> S;
  int N = S.size();

  map<char, vector<int>> m;
  rep(i, N)
    m[S[i]].push_back(i);

  unsigned long long ans = 0;
  rep(i, N) {
    priority_queue_rev<int> q;
    for (const auto& [_, v]:m)
      if (auto it = all(lower_bound, v, i); it != v.end())
        q.push(*it);

    int n = 0, before = i;
    while (!q.empty()) {
      int p = q.top(); q.pop();
      ans += 1ULL * n * (p-before);
      ++n;
      before = p;
    }
    ans += 1ULL * n * (N-before);
  }
  cout << fixed << setprecision(15) << 1.0 * ans / (1ULL*N*(N+1)/2) << endl;

  return 0;
}
0