結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-26 23:31:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 840 bytes |
| コンパイル時間 | 2,019 ms |
| コンパイル使用メモリ | 192,600 KB |
| 最終ジャッジ日時 | 2025-01-07 08:58:42 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 WA * 1 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
long long sum_cnt;
long long calc(int l, int r) {
return (r - l - 1) * (r - l) / 2;
}
long long cnt(int c) {
long long res = 0;
int pre = -1;
bool in = false;
for (int i = 0; i < n; i++) {
if (s[i] != c + 'a') continue;
in = true;
res += calc(pre, i);
pre = i;
}
if (s.back() != c + 'a') res += calc(pre, n);
if (!in) return 0;
return sum_cnt - res;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> s;
n = (int) s.size();
sum_cnt = 1LL * n * (n + 1) / 2;
long long tot = 0;
cerr << sum_cnt << endl;
for (int i = 0; i < 26; i++) {
tot += cnt(i);
cerr << "i = " << i << " " << cnt(i) << endl;
}
cout << setprecision(20) << fixed << 1.0 * tot / sum_cnt << endl;
return 0;
}