結果

問題 No.852 連続部分文字列
ユーザー tkmst201tkmst201
提出日時 2021-02-24 23:15:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,680 ms / 3,153 ms
コード長 1,097 bytes
コンパイル時間 2,163 ms
コンパイル使用メモリ 205,860 KB
実行使用メモリ 137,132 KB
最終ジャッジ日時 2023-10-25 04:34:23
合計ジャッジ時間 22,541 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 32 ms
5,564 KB
testcase_14 AC 15 ms
4,536 KB
testcase_15 AC 53 ms
6,968 KB
testcase_16 AC 33 ms
5,552 KB
testcase_17 AC 45 ms
6,440 KB
testcase_18 AC 57 ms
7,232 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 26 ms
5,172 KB
testcase_21 AC 58 ms
7,232 KB
testcase_22 AC 19 ms
4,764 KB
testcase_23 AC 41 ms
5,996 KB
testcase_24 AC 23 ms
4,984 KB
testcase_25 AC 39 ms
5,912 KB
testcase_26 AC 56 ms
7,232 KB
testcase_27 AC 33 ms
5,648 KB
testcase_28 AC 45 ms
6,440 KB
testcase_29 AC 60 ms
7,232 KB
testcase_30 AC 12 ms
4,464 KB
testcase_31 AC 60 ms
7,496 KB
testcase_32 AC 62 ms
7,760 KB
testcase_33 AC 1,668 ms
137,132 KB
testcase_34 AC 1,680 ms
137,132 KB
testcase_35 AC 1,675 ms
137,132 KB
testcase_36 AC 1,673 ms
137,132 KB
testcase_37 AC 1,669 ms
137,132 KB
testcase_38 AC 1,669 ms
137,132 KB
testcase_39 AC 1,671 ms
137,132 KB
testcase_40 AC 1,677 ms
137,132 KB
testcase_41 AC 1,669 ms
137,132 KB
testcase_42 AC 1,467 ms
137,132 KB
testcase_43 AC 1,158 ms
137,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	string S;
	cin >> S;
	const int N = S.size();
	vector pos(N, vector(26, N));
	for (int i = N - 2; i >= 0; --i) {
		REP(j, 26) pos[i][j] = j == S[i + 1] - 'a' ? i + 1 : pos[i + 1][j];
	}
	
	ll ans = 0;
	REP(i, N) {
		bool done[26] {};
		for (int p = i, cnt = 0; p < N;) {
			++cnt;
			done[S[p] - 'a'] = true;
			int np = N;
			REP(j, 26) if (!done[j]) chmin(np, pos[i][j]);
			ans += (np - p) * cnt;
			p = np;
		}
	}
	printf("%.17f\n", (double)ans / ((ll)N * (N + 1) / 2));
}
0