結果

問題 No.852 連続部分文字列
ユーザー heno239heno239
提出日時 2019-07-26 21:48:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,415 ms / 3,153 ms
コード長 2,167 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 110,320 KB
実行使用メモリ 105,672 KB
最終ジャッジ日時 2023-09-15 01:05:00
合計ジャッジ時間 18,219 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 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 2 ms
4,380 KB
testcase_13 AC 29 ms
5,272 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 47 ms
7,636 KB
testcase_16 AC 28 ms
5,196 KB
testcase_17 AC 40 ms
7,692 KB
testcase_18 AC 49 ms
7,744 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 23 ms
4,980 KB
testcase_21 AC 51 ms
7,688 KB
testcase_22 AC 17 ms
4,632 KB
testcase_23 AC 35 ms
7,696 KB
testcase_24 AC 20 ms
4,656 KB
testcase_25 AC 34 ms
5,520 KB
testcase_26 AC 50 ms
7,636 KB
testcase_27 AC 30 ms
5,280 KB
testcase_28 AC 39 ms
7,716 KB
testcase_29 AC 51 ms
7,780 KB
testcase_30 AC 10 ms
4,376 KB
testcase_31 AC 53 ms
7,768 KB
testcase_32 AC 54 ms
7,736 KB
testcase_33 AC 1,415 ms
105,524 KB
testcase_34 AC 1,413 ms
105,648 KB
testcase_35 AC 1,413 ms
105,644 KB
testcase_36 AC 1,413 ms
105,516 KB
testcase_37 AC 1,407 ms
105,564 KB
testcase_38 AC 1,413 ms
105,564 KB
testcase_39 AC 1,409 ms
105,672 KB
testcase_40 AC 1,409 ms
105,524 KB
testcase_41 AC 1,411 ms
105,616 KB
testcase_42 AC 1,226 ms
105,560 KB
testcase_43 AC 942 ms
105,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

//vector<int> loc[26];

int nex[1000000][26];

void solve() {
	string s; cin >> s;
	int n = s.length();
	/*rep(i, n) {
		loc[s[i]-'a'].push_back(i);
	}
	rep(i, 26)loc[i].push_back(n);*/
	vector<int> memo(26, n);
	per(i, n) {
		int z = s[i] - 'a';
		memo[z] = i;
		rep(j, 26) {
			nex[i][j] = memo[j];
		}
	}

	ll ans = 0;
	rep(i, n) {
		int cur = i;
		bool used[26] = {};
		used[s[i] - 'a'] = true;
		int tmp = 1;
		while (cur < n) {
			int mi = n; int chk=-1;
			rep(j, 26) {
				if (used[j])continue;
				//int id = upper_bound(loc[j].begin(), loc[j].end(), cur) - loc[j].begin();
				/*if (loc[j][id] < mi) {
					mi = loc[j][id];
					chk = j;
				}*/
				if (nex[cur][j] < mi) {
					mi = nex[cur][j]; chk = j;
				}
			}
			if (chk < 0) {
				ans += (ll)(n-cur) * tmp;
				break;
			}
			used[chk] = true;
			ll dif = mi - cur;
			ans += dif * tmp;
		   // cout << cur<<" "<<tmp << " " << dif << endl;
			cur = mi;
			tmp++;
		}
		//cout << ans << endl;
	}
	//cout << ans << endl;
	ll ss = (ll)n*(n + 1) / 2;
	cout << ans / (ld)ss << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
//stop
	return 0;
}
0