結果

問題 No.852 連続部分文字列
ユーザー ninja
提出日時 2019-07-26 21:59:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 760 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 172,556 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-02 07:13:09
合計ジャッジ時間 4,144 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  ll n = s.size();
  ll div = n * (n + 1) / 2;
  ll sum = 0;
  set<char> st;
  for (char &c : s) st.insert(c);
  for (auto &c : st) {
    ll sub = n * (n + 1) / 2;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == c) {
        if (cnt) {
          sub -= (cnt * (cnt + 1) / 2);
        }
        cnt = 0;
      } else {
        cnt++;
      }
    }
    if (cnt) sub -= (cnt * (cnt + 1) / 2);
    sum += sub;
  }

  printf("%.12lf\n", (double) sum / div);
  return 0;
}
0