結果
問題 | No.852 連続部分文字列 |
ユーザー |
|
提出日時 | 2019-07-31 16:44:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 3,153 ms |
コード長 | 485 bytes |
コンパイル時間 | 2,089 ms |
コンパイル使用メモリ | 196,312 KB |
最終ジャッジ日時 | 2025-01-07 10:16:40 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string S; cin >> S; vector<int64_t> dp(S.size() + 1); vector<int> pre(256, -1); for (int i = 0; i < S.size(); ++i) { dp[i + 1] = dp[i] + i - pre[S[i]]; pre[S[i]] = i; } int64_t sdp = accumulate(dp.begin(), dp.end(), 0LL); int64_t n = 1LL * S.size() * (S.size() + 1) / 2; double ans = 1.0 * sdp / n; cout << fixed << setprecision(9) << ans << endl; return 0; }