結果

問題 No.852 連続部分文字列
ユーザー tarattata1tarattata1
提出日時 2019-07-26 22:23:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 3,153 ms
コード長 1,236 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 85,048 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 02:04:19
合計ジャッジ時間 3,000 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;



char str[1000005];
int main(int argc, char* argv[])
{
    scanf("%s", str);

    map<char,int> z;
    map<char,double> val;
    int len=strlen(str);
    int i;
    for(i=0; i<len; i++) {
        auto it = z.find(str[i]);
        int tmp=0;
        if(it!=z.end()) {
            tmp=it->second+1;
        }
        if(i-tmp>0) {
            val[str[i]] += (double)(i-tmp)*(i-tmp+1)/2;
        }
        z[str[i]]=i;
    }

    double ans=0;
    auto it=z.begin();
    for(; it!=z.end(); ++it) {
        int tmp=it->second+1;
        if(len-tmp>0) {
            val[it->first] += (double)(len-tmp)*(len-tmp+1)/2;
        }
        ans += ((double)len*(len+1)/2-val[it->first]);
    }
    printf("%.10lf\n", ans / ((double)len*(len+1)/2) );

    return 0;
}
0