結果

問題 No.852 連続部分文字列
ユーザー kuuso1kuuso1
提出日時 2019-07-26 22:38:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,405 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 176,928 KB
実行使用メモリ 9,480 KB
最終ジャッジ日時 2023-09-15 02:32:18
合計ジャッジ時間 10,404 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 128 ms
4,380 KB
testcase_14 AC 57 ms
4,380 KB
testcase_15 AC 210 ms
4,380 KB
testcase_16 AC 127 ms
4,376 KB
testcase_17 AC 178 ms
4,376 KB
testcase_18 AC 227 ms
4,384 KB
testcase_19 AC 16 ms
4,376 KB
testcase_20 AC 100 ms
4,380 KB
testcase_21 AC 233 ms
4,376 KB
testcase_22 AC 73 ms
4,380 KB
testcase_23 AC 158 ms
4,376 KB
testcase_24 AC 88 ms
4,380 KB
testcase_25 AC 151 ms
4,376 KB
testcase_26 AC 226 ms
4,380 KB
testcase_27 AC 132 ms
4,380 KB
testcase_28 AC 179 ms
4,380 KB
testcase_29 AC 233 ms
4,380 KB
testcase_30 AC 43 ms
4,376 KB
testcase_31 AC 241 ms
4,376 KB
testcase_32 AC 249 ms
4,376 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }
string S;
int N;

double calc(int len){
	map<char, int> dl;
	int l = 0;
	map<char, int> dr;
	int r = 0;
	double cnt = 0;
	for(int i=0;i<N;i++){
		if(l < i) l = i;
		if(r < i) r = i;
		while(l < N){
			if(dl.find(S[l]) != dl.end()){
				dl[S[l]]++;
				l++;
				continue;
			}
			if(dl.size() < len - 1){
				dl.insert(make_pair(S[l], 1));
				l++;
				continue;
			}
			break;
		}
		while(r < N){
			if(dr.find(S[r]) != dr.end()){
				dr[S[r]]++;
				r++;
				continue;
			}
			if(dr.size() < len){
				dr.insert(make_pair(S[r], 1));
				r++;
				continue;
			}
			break;
		}
		if(dr.size() == len){
			cnt += r - l;
		}
		if(dl.find(S[i]) != dl.end()){
			dl[S[i]]--;
			if(dl[S[i]] == 0) dl.erase(S[i]);
		}
		if(dr.find(S[i]) != dr.end()){
			dr[S[i]]--;
			if(dr[S[i]] == 0) dr.erase(S[i]);
		}
	}
	//Console.WriteLine("len:{0}, cnt:{1}",len, cnt);
	
	double tot = (double) N * (double) (N + 1) / 2.0;
	return (double) len * cnt / tot;
	
}






int main(){
	
	cin >> S;
	N = S.length();
	double ret = 0;
	for(int i=1;i<=26;i++){
		ret += calc(i);
	}
	printf("%.12f\n",ret);
	
    return 0;
}
0