結果

問題 No.852 連続部分文字列
ユーザー le_panda_noirle_panda_noir
提出日時 2020-05-31 12:09:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 890 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 94,876 KB
実行使用メモリ 10,132 KB
最終ジャッジ日時 2024-04-28 13:40:54
合計ジャッジ時間 18,944 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 24 ms
6,944 KB
testcase_14 AC 11 ms
6,944 KB
testcase_15 AC 39 ms
6,940 KB
testcase_16 AC 25 ms
6,944 KB
testcase_17 AC 33 ms
6,944 KB
testcase_18 AC 43 ms
6,944 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 19 ms
6,940 KB
testcase_21 AC 43 ms
6,944 KB
testcase_22 AC 15 ms
6,944 KB
testcase_23 AC 30 ms
6,940 KB
testcase_24 AC 17 ms
6,940 KB
testcase_25 AC 28 ms
6,944 KB
testcase_26 AC 41 ms
6,940 KB
testcase_27 AC 25 ms
6,944 KB
testcase_28 AC 32 ms
6,940 KB
testcase_29 AC 44 ms
6,944 KB
testcase_30 AC 9 ms
6,940 KB
testcase_31 AC 44 ms
6,940 KB
testcase_32 AC 46 ms
6,940 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 <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
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);

  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 += n * (p-before);
      ++n;
      before = p;
    }
    ans += n * (N-before);
  }
  cout << 1.0 * ans / (N*(N+1)/2) << endl;

  return 0;
}
0