結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
1119_2916
|
| 提出日時 | 2019-08-01 17:46:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 415 ms / 3,153 ms |
| コード長 | 1,669 bytes |
| コンパイル時間 | 1,652 ms |
| コンパイル使用メモリ | 174,480 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 07:44:07 |
| 合計ジャッジ時間 | 6,871 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)
//int dxy[5] = {0, 1, 0, -1, 0};
// cmd
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
string st;
cin >> st;
int n = st.size();
vi pos(26, 0);
vi cnt(27, 0);
rep(i, n) {
pos[st[i] - 'a'] = i+1;
/*
rep(j, pos.size()) {
cout << pos[j] << " ";
}
cout << endl;
*/
vi sorted = pos;
sorted.emplace_back(0);
sort(all(sorted));
reverse(all(sorted));
Rep(j, sorted.size()) {
cnt[j] += sorted[j-1] - sorted[j];
}
}
int sum = 0;
rep(i, cnt.size()) {
sum += cnt[i] * i;
//std::cout << cnt[i] << std::endl;
}
cout << Decimal << (double)sum / (n * (n+1) / 2.0) << endl;
return 0;
}
1119_2916