結果

問題 No.852 連続部分文字列
ユーザー edamame882edamame882
提出日時 2019-07-26 22:19:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 3,153 ms
コード長 1,399 bytes
コンパイル時間 2,990 ms
コンパイル使用メモリ 175,140 KB
実行使用メモリ 11,076 KB
最終ジャッジ日時 2023-09-15 01:59:45
合計ジャッジ時間 4,216 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 3 ms
4,384 KB
testcase_33 AC 57 ms
9,768 KB
testcase_34 AC 58 ms
10,104 KB
testcase_35 AC 59 ms
10,108 KB
testcase_36 AC 58 ms
10,108 KB
testcase_37 AC 58 ms
10,060 KB
testcase_38 AC 58 ms
9,796 KB
testcase_39 AC 58 ms
10,076 KB
testcase_40 AC 58 ms
10,100 KB
testcase_41 AC 58 ms
10,132 KB
testcase_42 AC 35 ms
10,068 KB
testcase_43 AC 52 ms
11,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

ll sum(ll x){
  return x*(x+1)/2LL;
}
int main(){

  string s;
  cin >> s;

  map<char,VI> mp;
  rep(i,s.size()){
    mp[s[i]].push_back(i);
  }
  ll n = s.size();
  double ans = 0;

  for(auto x: mp){
    x.second.push_back(n);
    ans += sum(n);
    // cout << "+" << sum(n) << endl;
    rep(i,x.second.size() - 1){
      if(i == 0) { ans -= sum(x.second[0]); }
      ans -=  sum(x.second[i+1] - x.second[i] - 1);
      //cout << "-" << sum(x.second[i+1] - x.second[i] - 1) << endl;
    }
    // cout << ans << endl;
  }

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