結果

問題 No.852 連続部分文字列
ユーザー edamame882
提出日時 2019-07-26 22:19:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 60 ms / 3,153 ms
コード長 1,399 bytes
コンパイル時間 1,671 ms
コンパイル使用メモリ 177,760 KB
実行使用メモリ 11,080 KB
最終ジャッジ日時 2024-07-02 07:40:49
合計ジャッジ時間 3,728 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

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