結果
問題 |
No.852 連続部分文字列
|
ユーザー |
![]() |
提出日時 | 2020-06-16 17:01:18 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 25 ms / 3,153 ms |
コード長 | 539 bytes |
コンパイル時間 | 1,858 ms |
コンパイル使用メモリ | 160,996 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-03 11:53:48 |
合計ジャッジ時間 | 4,289 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.16 17:01:13 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { string s; cin >> s; ll n = s.size(); double ans = n * (n + 1) *(n + 1) / 2 - n * (n + 1) * (2 * n + 1) / 6; vector< int > pre(26, -1); for (int i = 0; i < n; i++) { if (pre[s[i] - 'a'] != -1) { ans -= (n-i)*(pre[s[i]-'a'] + 1); } pre[s[i] - 'a'] = i; } printf("%.10f\n",ans*2/n/(n+1)); return 0; }