結果

問題 No.852 連続部分文字列
ユーザー le_panda_noir
提出日時 2020-05-31 12:09:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 890 bytes
コンパイル時間 1,289 ms
コンパイル使用メモリ 90,472 KB
最終ジャッジ日時 2025-01-10 20:02:12
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 11
権限があれば一括ダウンロードができます

ソースコード

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