結果

問題 No.852 連続部分文字列
ユーザー tempura_pptempura_pp
提出日時 2019-03-29 16:44:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,650 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 103,012 KB
実行使用メモリ 221,840 KB
最終ジャッジ日時 2024-04-24 16:38:42
合計ジャッジ時間 10,683 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 10 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 215 ms
23,552 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 204 ms
19,712 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 213 ms
21,888 KB
testcase_26 AC 219 ms
23,808 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 228 ms
24,576 KB
testcase_33 AC 420 ms
221,584 KB
testcase_34 AC 425 ms
221,588 KB
testcase_35 AC 400 ms
221,584 KB
testcase_36 AC 401 ms
221,584 KB
testcase_37 WA -
testcase_38 AC 408 ms
221,588 KB
testcase_39 AC 410 ms
221,584 KB
testcase_40 AC 406 ms
221,584 KB
testcase_41 AC 406 ms
221,588 KB
testcase_42 AC 408 ms
221,584 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


struct Xor128{
    unsigned x,y,z,w;
 
    Xor128(unsigned w_=88675123):x(123456789),y(362436069),z(521288629),w(w_){};
 
    inline unsigned xor128(){
        unsigned t;
        t = x^(x<<11);
        x = y;
        y = z;
        z = w;
        return w = (w^(w>>19))^(t^(t>>8));
    }
 
    int nextInt(int x,int y){
		if(x>y)swap(x,y);
        return xor128()%(y-x)+x;
    }
 
    double nextDouble(double a,double b){
        return (double)(xor128()&0xffff)/0xffff*(b-a)+a;
    }
 
};
int main(){
    string s;
    cin>>s;
    ll n=s.size();
    auto rnd=Xor128();
    set<ll> st;
    ll sum=0;
    ll cumsum[1000001][26];
    rep(i, n) rep(j, 26) cumsum[i + 1][j] = cumsum[i][j] + (s[i] - 'a' == j ? 1 : 0);
    rep(i,300000){
        int l=rnd.nextInt(0, n);
        int r=rnd.nextInt(1, n+1);
        if(l==r)continue;
        if(l>r)swap(l,r);
        if(st.count(n*r+l))continue;
        st.insert(n*r+l);
        int cnt=0;
        rep(j, 26) if (cumsum[r][j] - cumsum[l][j] > 0) ++ cnt;
        sum+=cnt;
        if(st.size()==n*(n+1)/2)break;
    }
    cout<<1.0*sum/st.size()<<endl;

    return 0;
}
0