結果

問題 No.852 連続部分文字列
ユーザー pionepione
提出日時 2019-07-27 00:54:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 59 ms / 3,153 ms
コード長 2,341 bytes
コンパイル時間 1,346 ms
コンパイル使用メモリ 145,976 KB
実行使用メモリ 6,228 KB
最終ジャッジ日時 2023-09-15 05:24:14
合計ジャッジ時間 3,886 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,384 KB
testcase_19 AC 1 ms
4,388 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 3 ms
4,384 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 4 ms
4,384 KB
testcase_33 AC 57 ms
6,152 KB
testcase_34 AC 59 ms
6,172 KB
testcase_35 AC 58 ms
6,228 KB
testcase_36 AC 58 ms
6,212 KB
testcase_37 AC 58 ms
6,068 KB
testcase_38 AC 59 ms
6,152 KB
testcase_39 AC 59 ms
6,052 KB
testcase_40 AC 59 ms
6,064 KB
testcase_41 AC 58 ms
6,048 KB
testcase_42 AC 47 ms
6,172 KB
testcase_43 AC 59 ms
6,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()
#define MP(n, m) make_pair(n, m);

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;
using ul = unsigned long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

void printv(VI& v){
  REP(i,v.size()) cout << v[i] << " ";
  cout << endl;
}

int vtotal(VI& v){
  int total=0;
  REP(i,v.size()) total+=v[i];
  return total;
}

// int main()
// {
//   cin.tie( 0 );
//   ios::sync_with_stdio( false );

//   // string n;
// 	// getline(cin,n);

//   string S;
//   cin>>S;

//   int dp = 0, use[26];
//   int64_t sum = 0;
//   for (int i = 0;i < 26;++ i) use[i] = -1;
//   for (int i = 0;i < S.size(); ++ i) {
//     dp += i - use[S[i] - 'a'];
//     sum += dp;
//     use[S[i] - 'a'] = i;
//   }

//   int n=s.size();
//   int sum=0,count=0;
//   REP(i,n){
    
//     map<char,int> m;
//     REP(j,n-i){
//       m.insert(make_pair(s[i+j],0));
//       count++;
//       sum+=m.size();
//       // cout<<sum<<" "<<count<<endl;
//     }
//   }
//   // cout<<sum<<" "<<count<<endl;
//   double ans=(double)sum/count;
//   cout<<std::setprecision(10)<<ans<<endl;

//   return 0;
// }


ll solve(string S, char c)
{
    ll las = -1;
    ll N = S.length();
    ll ret = N * (N + 1) / 2;
    S += c;
    REP(i, S.length() + 1)
    {
        if (S[i] == c)
        {
            ret -= (i - las) * (i - las - 1) / 2;
            las = i;
        }
    }
    return ret;
}

int main()
{
    string S;
    cin >> S;
    ll su = 0, N = S.length();
    REP(c, 26)
    {
        su += solve(S, (char)('a' + c));
    }
    cout << (double)su / (N * (N + 1) / 2);
}
0