結果

問題 No.852 連続部分文字列
ユーザー le_panda_noirle_panda_noir
提出日時 2020-05-31 12:23:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,721 ms / 3,153 ms
コード長 966 bytes
コンパイル時間 1,071 ms
コンパイル使用メモリ 105,244 KB
実行使用メモリ 10,256 KB
最終ジャッジ日時 2024-04-28 13:58:02
合計ジャッジ時間 20,517 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 26 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 43 ms
5,376 KB
testcase_16 AC 25 ms
5,376 KB
testcase_17 AC 37 ms
5,376 KB
testcase_18 AC 46 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 20 ms
5,376 KB
testcase_21 AC 49 ms
5,376 KB
testcase_22 AC 15 ms
5,376 KB
testcase_23 AC 32 ms
5,376 KB
testcase_24 AC 18 ms
5,376 KB
testcase_25 AC 29 ms
5,376 KB
testcase_26 AC 47 ms
5,376 KB
testcase_27 AC 28 ms
5,376 KB
testcase_28 AC 36 ms
5,376 KB
testcase_29 AC 46 ms
5,376 KB
testcase_30 AC 9 ms
5,376 KB
testcase_31 AC 48 ms
5,376 KB
testcase_32 AC 53 ms
5,376 KB
testcase_33 AC 1,693 ms
9,872 KB
testcase_34 AC 1,681 ms
10,240 KB
testcase_35 AC 1,721 ms
10,128 KB
testcase_36 AC 1,699 ms
9,612 KB
testcase_37 AC 1,688 ms
10,128 KB
testcase_38 AC 1,709 ms
9,744 KB
testcase_39 AC 1,689 ms
10,256 KB
testcase_40 AC 1,690 ms
10,252 KB
testcase_41 AC 1,679 ms
9,872 KB
testcase_42 AC 1,262 ms
10,256 KB
testcase_43 AC 1,225 ms
9,748 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