結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  string s;
  cin>>s;
  int n = s.size();
  ll total = n*(n+1)/2;
  ll sm = 0;
  ll dp = 0;
  vector<int> used(26,-1);
  rep(i,n) {
    dp+=i-used[(int)(s[i]-'a')];
    sm += dp;
    used[(int)(s[i]-'a')]=i;
  }
  cout << (1.0*sm)/total << endl;
  return 0;
}
0