結果

問題 No.852 連続部分文字列
ユーザー chocorusk
提出日時 2019-07-26 21:53:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 260 ms / 3,153 ms
コード長 1,087 bytes
コンパイル時間 2,598 ms
コンパイル使用メモリ 96,968 KB
実行使用メモリ 5,424 KB
最終ジャッジ日時 2024-07-02 07:06:02
合計ジャッジ時間 6,766 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main()
{
string s; cin>>s;
int n=s.size();
ll sum[27]={};
for(int i=1; i<=26; i++){
int r=-1;
int cnt[26]={};
int x=0;
for(int l=0; l<n; l++){
while(r<n && x<=i){
r++;
cnt[s[r]-'a']++;
if(cnt[s[r]-'a']==1) x++;
}
sum[i]+=(r-l);
cnt[s[l]-'a']--;
if(cnt[s[l]-'a']==0) x--;
}
}
ll tot=0;
for(ll i=1; i<=26; i++){
tot+=(sum[i]-sum[i-1])*i;
}
ll p=(ll)n*(ll)(n+1)/2;
double ans=(double)tot/(double)p;
printf("%.6lf\n", ans);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0