結果

問題 No.852 連続部分文字列
ユーザー Mayimg
提出日時 2019-07-26 23:00:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 918 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 194,448 KB
最終ジャッジ日時 2025-01-07 08:32:54
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
long long sum_cnt;
void calc_sum() {
  for (int len = 1; len <= n; len++) {
    sum_cnt += 1LL * (n - len + 1);
  }
}
long long calc(int l, int r) {
  return (r - l - 1) * (r - l) / 2;
}
long long cnt(int c) {
  long long res = 0;
  int pre = -1;
  bool in = false;
  for (int i = 0; i < n; i++) {
    if (s[i] != c + 'a') continue;
    in = true;
    res += calc(pre, i);
    pre = i;
  } 
  if (s.back() != c + 'a') res += calc(pre, n);
  if (!in) return 0;
  return sum_cnt - res;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> s;
  n = (int) s.size();
  calc_sum();
  long long tot = 0;
  cerr << sum_cnt << endl;
  for (int i = 0; i < 26; i++) {
    tot += cnt(i);
    cerr << "i = " << i << " " << cnt(i) << endl;
  }
  cout << setprecision(20) << fixed << 1.0 * tot / sum_cnt << endl;
  return 0;
}
0