結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
manjuuu_onsen
|
| 提出日時 | 2020-09-10 17:33:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 3,153 ms |
| コード長 | 604 bytes |
| コンパイル時間 | 1,640 ms |
| コンパイル使用メモリ | 172,112 KB |
| 実行使用メモリ | 16,144 KB |
| 最終ジャッジ日時 | 2024-12-23 14:13:22 |
| 合計ジャッジ時間 | 3,327 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
string s; ll n;
cin >> s; n = s.size();
vector<vector<ll>> pos(26);
for(auto &i: pos)i.push_back(-1);
for(ll i = 0; i < n; i++) {
pos[s[i] - 'a'].push_back(i);
}
for(auto &i: pos)i.push_back(n);
ll unit = n * (n + 1) / 2;
ll sum = 0;
for(ll i = 0; i < 26; i++) {
ll cur = unit;
ll m = pos[i].size();
for(ll j = 0; j < m - 1; j++) {
ll num = pos[i][j+1] - pos[i][j];
cur -= num * (num - 1) / 2;
}
sum += cur;
}
cout << fixed <<setprecision(12) << (double)sum / ((n) * (n+1) / 2) << endl;
}
manjuuu_onsen