結果

問題 No.852 連続部分文字列
ユーザー tkmst201tkmst201
提出日時 2021-02-24 23:27:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,260 ms / 3,153 ms
コード長 1,197 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 209,480 KB
実行使用メモリ 137,176 KB
最終ジャッジ日時 2023-10-25 04:42:57
合計ジャッジ時間 17,847 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 24 ms
5,612 KB
testcase_14 AC 12 ms
4,584 KB
testcase_15 AC 38 ms
7,012 KB
testcase_16 AC 24 ms
5,600 KB
testcase_17 AC 33 ms
6,484 KB
testcase_18 AC 41 ms
7,276 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 19 ms
5,220 KB
testcase_21 AC 42 ms
7,276 KB
testcase_22 AC 14 ms
4,812 KB
testcase_23 AC 29 ms
6,044 KB
testcase_24 AC 17 ms
5,032 KB
testcase_25 AC 28 ms
5,956 KB
testcase_26 AC 41 ms
7,276 KB
testcase_27 AC 25 ms
5,692 KB
testcase_28 AC 33 ms
6,484 KB
testcase_29 AC 42 ms
7,276 KB
testcase_30 AC 9 ms
4,512 KB
testcase_31 AC 43 ms
7,540 KB
testcase_32 AC 45 ms
7,804 KB
testcase_33 AC 1,253 ms
137,176 KB
testcase_34 AC 1,259 ms
137,176 KB
testcase_35 AC 1,256 ms
137,176 KB
testcase_36 AC 1,260 ms
137,176 KB
testcase_37 AC 1,256 ms
137,176 KB
testcase_38 AC 1,259 ms
137,176 KB
testcase_39 AC 1,251 ms
137,176 KB
testcase_40 AC 1,253 ms
137,176 KB
testcase_41 AC 1,258 ms
137,176 KB
testcase_42 AC 734 ms
137,176 KB
testcase_43 AC 943 ms
137,176 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] {};
		priority_queue<int, vector<int>, greater<int>> pq;
		REP(j, 26) if (j != S[i] - 'a') pq.emplace(pos[i][j]);
		pq.emplace(N);
		for (int p = i, cnt = 0; p < N;) {
			++cnt;
			done[S[p] - 'a'] = true;
			const int np = pq.top(); pq.pop();
			ans += (np - p) * cnt;
			p = np;
		}
	}
	printf("%.17f\n", (double)ans / ((ll)N * (N + 1) / 2));
}
0