結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
le_panda_noir
|
| 提出日時 | 2020-05-31 12:23:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,062 ms / 3,153 ms |
| コード長 | 966 bytes |
| コンパイル時間 | 1,459 ms |
| コンパイル使用メモリ | 100,100 KB |
| 最終ジャッジ日時 | 2025-01-10 20:02:39 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
template<class T>using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
int main() {
string S; cin >> S;
int N = S.size();
map<char, vector<int>> m;
rep(i, N)
m[S[i]].push_back(i);
unsigned long long ans = 0;
rep(i, N) {
priority_queue_rev<int> q;
for (const auto& [_, v]:m)
if (auto it = all(lower_bound, v, i); it != v.end())
q.push(*it);
int n = 0, before = i;
while (!q.empty()) {
int p = q.top(); q.pop();
ans += 1ULL * n * (p-before);
++n;
before = p;
}
ans += 1ULL * n * (N-before);
}
cout << fixed << setprecision(15) << 1.0 * ans / (1ULL*N*(N+1)/2) << endl;
return 0;
}
le_panda_noir