結果
問題 | No.852 連続部分文字列 |
ユーザー |
![]() |
提出日時 | 2019-07-26 21:40:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 945 ms / 3,153 ms |
コード長 | 1,582 bytes |
コンパイル時間 | 1,734 ms |
コンパイル使用メモリ | 173,528 KB |
実行使用メモリ | 235,080 KB |
最終ジャッジ日時 | 2024-07-02 06:48:04 |
合計ジャッジ時間 | 13,838 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h>using namespace std;using lint = long long;template<class T = int> using V = vector<T>;template<class T = int> using VV = V< V<T> >;struct DisjointSparseTable {using T = int;static T op(const T& x, const T& y) { return x | y; }const int n;VV<T> t;template<class Itr> DisjointSparseTable(Itr first, Itr last) :n(distance(first, last)), t(__lg(n) + 1, V<T>(first, last)) {for (int k = 1; k < (int) t.size(); ++k) {for (int i0 = 1 << k; i0 < n; i0 += 1 << k + 1) {for (int i = i0 + 1; i < min(i0 + (1 << k), n); ++i) {t[k][i] = op(t[k][i - 1], t[k][i]);}for (int i = i0 - 2; i >= i0 - (1 << k); --i) {t[k][i] = op(t[k][i], t[k][i + 1]);}}}}T acc(int l, int r) const {assert(l < r);if (l == --r) return t[0][l];int k = __lg(l ^ r);return op(t[k][l], t[k][r]);}};int main() {cin.tie(nullptr); ios::sync_with_stdio(false);string s; cin >> s;int n = s.size();V<> a(n);for (int i = 0; i < n; ++i) {a[i] = 1 << s[i] - 'a';}DisjointSparseTable dst(begin(a), end(a));VV<> b(n, V<>(27));for (int k = 1; k <= 26; ++k) {int r = 0;for (int l = 0; l < n; ++l) {while (r < n and __builtin_popcount(dst.acc(l, r + 1)) <= k) ++r;b[l][k] = r;}}lint sum = 0;for (int l = 0; l < n; ++l) {b[l][0] = l;for (int k = 1; k <= 26; ++k) {sum += (b[l][k] - b[l][k - 1]) * k;}}cout << fixed << setprecision(15) << sum / (0.5 * n * (n + 1)) << '\n';}