結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2019-07-26 22:39:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 3,153 ms |
| コード長 | 599 bytes |
| コンパイル時間 | 1,981 ms |
| コンパイル使用メモリ | 192,652 KB |
| 最終ジャッジ日時 | 2025-01-07 08:14:32 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#include <bits/stdc++.h>
int main() {
std::cin.tie(0); std::cin.sync_with_stdio(false);
std::string s; std::cin >> s;
int n = s.length();
auto f = [&] (int x) {
return (long long)x * (x + 1) / 2;
};
auto cal = [&] (char c) {
long long ans = f(n);
int prv = -1;
for (int i = 0; i < n; i++) {
if (s.at(i) == c) {
ans -= f(i - prv - 1);
prv = i;
}
}
ans -= f(n - prv - 1);
return ans;
};
long long ans = 0;
for (int i = 0; i < 26; i++) {
ans += cal('a' + i);
}
std::cout << (double)ans / f(n) << std::endl;
return 0;
}
ngtkana