結果

問題 No.852 連続部分文字列
ユーザー mint6421mint6421
提出日時 2019-08-01 17:54:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,694 ms / 3,153 ms
コード長 1,380 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 200,900 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 17:41:48
合計ジャッジ時間 22,117 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 30 ms
4,376 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 49 ms
4,380 KB
testcase_16 AC 31 ms
4,376 KB
testcase_17 AC 42 ms
4,376 KB
testcase_18 AC 53 ms
4,380 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 24 ms
4,380 KB
testcase_21 AC 54 ms
4,380 KB
testcase_22 AC 18 ms
4,376 KB
testcase_23 AC 37 ms
4,380 KB
testcase_24 AC 21 ms
4,380 KB
testcase_25 AC 36 ms
4,376 KB
testcase_26 AC 52 ms
4,380 KB
testcase_27 AC 32 ms
4,376 KB
testcase_28 AC 42 ms
4,376 KB
testcase_29 AC 54 ms
4,376 KB
testcase_30 AC 11 ms
4,380 KB
testcase_31 AC 56 ms
4,376 KB
testcase_32 AC 58 ms
4,376 KB
testcase_33 AC 1,691 ms
4,376 KB
testcase_34 AC 1,688 ms
4,380 KB
testcase_35 AC 1,694 ms
4,380 KB
testcase_36 AC 1,688 ms
4,376 KB
testcase_37 AC 1,687 ms
4,376 KB
testcase_38 AC 1,689 ms
4,376 KB
testcase_39 AC 1,687 ms
4,380 KB
testcase_40 AC 1,689 ms
4,376 KB
testcase_41 AC 1,689 ms
4,376 KB
testcase_42 AC 1,521 ms
4,376 KB
testcase_43 AC 826 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  string s;
  cin>>s;

  vector<int> a(30,0);
  vector<int> pre(30,-1);

  rep(i,s.size()){
    int c=s[i]-'a';
    vector<int> p(30);
    rep(j,30){
      p[j]=pre[j];
    }
    int k=1;
    int t=-1;
    int e=-1,r=i;
    while(true){
      rep(j,30){
        if(j==c) continue;
        if(t<p[j]){
          t=p[j];
          e=j;
        }
      }
      if(t==-1){
        a[k]+=r+1;
        break;
      }else{
        a[k]+=r-t;
        p[e]=-1;
        r=t;
        k++;
        t=-1;
      }
    }
    pre[c]=i;
  }

  double sum=0;
  rep(i,30){
    sum+=i*a[i];
    //cout<<a[i]<<endl;
  }

  double n=s.size();

  printf("%.10lf\n",sum/(n*(n+1)/2));



}
0