結果
問題 |
No.852 連続部分文字列
|
ユーザー |
![]() |
提出日時 | 2023-08-02 05:29:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,892 ms / 3,153 ms |
コード長 | 854 bytes |
コンパイル時間 | 3,573 ms |
コンパイル使用メモリ | 255,956 KB |
最終ジャッジ日時 | 2025-02-15 21:26:28 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll mod=998244353; ll inf=100990999999999909; int main(){ string s; cin >> s; vector<ll>memo(100,-1); ll ans=0; for (ll i = 0; i < s.size(); i++) { map<ll,ll>mm; ll now=0; memo[s[i]-'a']=max(memo[s[i]-'a'],i); for (char c = 'a'; c <='z'; c++) { if (memo[c-'a']!=-1) { now++; mm[memo[c-'a']]++; } } ll pre=-1; for(auto v:mm){ ans+=now*(v.first-pre); pre=v.first; now--; } } ll n=s.size(); ll x=(n*(n+1))/2; ld y=ans; ld z=x; cout << setprecision(100) << y/z << endl; }