結果
問題 | No.852 連続部分文字列 |
ユーザー |
![]() |
提出日時 | 2019-08-06 15:26:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 3,153 ms |
コード長 | 529 bytes |
コンパイル時間 | 1,388 ms |
コンパイル使用メモリ | 167,948 KB |
実行使用メモリ | 12,396 KB |
最終ジャッジ日時 | 2024-07-18 13:57:53 |
合計ジャッジ時間 | 3,498 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; signed main(){ cout << setprecision(12) ; ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; int n=s.size(); ll dp[n+1]={}; //iを右端にしたときの文字列の種類数の総和 vector<int> pre(26,-1); double ans=0; for(int i=0;i<n;i++){ dp[i + 1] = dp[i] + i-pre[s[i]-'a']; pre[s[i]-'a'] = i; ans += dp[i+1]; } ans /= (double)n*(n+1)/2.0; cout<<ans<<endl; }