結果

問題 No.852 連続部分文字列
ユーザー definedefine
提出日時 2019-07-31 12:17:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 3,153 ms
コード長 1,658 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 165,896 KB
実行使用メモリ 20,028 KB
最終ジャッジ日時 2023-09-18 15:56:12
合計ジャッジ時間 3,702 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 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 1 ms
4,380 KB
testcase_13 AC 3 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,380 KB
testcase_17 AC 3 ms
4,384 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 3 ms
4,384 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 3 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 3 ms
4,384 KB
testcase_32 AC 3 ms
4,384 KB
testcase_33 AC 38 ms
19,920 KB
testcase_34 AC 38 ms
19,876 KB
testcase_35 AC 38 ms
19,900 KB
testcase_36 AC 38 ms
20,000 KB
testcase_37 AC 38 ms
19,928 KB
testcase_38 AC 38 ms
20,024 KB
testcase_39 AC 39 ms
19,920 KB
testcase_40 AC 38 ms
19,952 KB
testcase_41 AC 38 ms
20,028 KB
testcase_42 AC 38 ms
19,856 KB
testcase_43 AC 38 ms
20,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

string s;
int dp[1145141][2];
int near[30];
signed main() {
	cin >> s;
	fill(near, near + 26, -1);
	rep(i, s.size()) {
		dp[i + 1][0] += dp[i][0] + dp[i][1];
		dp[i + 1][1] += dp[i][1] + (i - near[s[i] - 'a']);
		near[s[i] - 'a'] = i;
	}
	printf("%.12lf\n", (double)(dp[s.size()][0] + dp[s.size()][1]) / (double)((s.size() + 1) * s.size() / 2));
}
0