結果

問題 No.852 連続部分文字列
ユーザー LayCurseLayCurse
提出日時 2019-07-26 21:42:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 231 ms / 3,153 ms
コード長 1,583 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 198,972 KB
実行使用メモリ 4,708 KB
最終ジャッジ日時 2023-09-15 00:53:39
合計ジャッジ時間 6,115 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 9 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 7 ms
4,380 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 9 ms
4,380 KB
testcase_27 AC 6 ms
4,376 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 10 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 10 ms
4,376 KB
testcase_32 AC 10 ms
4,376 KB
testcase_33 AC 230 ms
4,560 KB
testcase_34 AC 230 ms
4,452 KB
testcase_35 AC 231 ms
4,560 KB
testcase_36 AC 230 ms
4,448 KB
testcase_37 AC 229 ms
4,656 KB
testcase_38 AC 229 ms
4,444 KB
testcase_39 AC 230 ms
4,708 KB
testcase_40 AC 230 ms
4,572 KB
testcase_41 AC 229 ms
4,556 KB
testcase_42 AC 103 ms
4,588 KB
testcase_43 AC 161 ms
4,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(double x){
  printf("%.15f",x);
}
char S[1000002];
int N;
int cnt[26];
int main(){
  double res;
  int i, j, k, m;
  N = rd(S);
  for(i=0;i<N;i++){
    S[i] -= 'a';
  }
  res = 0;
  for(k=1;k<27;k++){
    j = 0;
    m = 0;
    for(i=0;i<26;i++){
      cnt[i] = 0;
    }
    for(i=0;i<N;i++){
      while(j<N && m<k){
        if((cnt[S[j]]++)==0){
          m++;
        }
        j++;
      }
      if(j==N && m<k){
        break;
      }
      res += N-j+1;
      if((--cnt[S[i]])==0){
        m--;
      }
    }
  }
  res /= (double)N*(N+1)/2;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// char S[1000002]; int N;
// int cnt[26];
// {
//   int i, j, k, m;
//   double res;
//   
//   rd(S@N);
//   rep(i,N) S[i] -= 'a';
// 
//   res = 0;
// 
//   rep(k,1,27){
//     j = 0;
//     m = 0;
//     rep(i,26) cnt[i] = 0;
//     rep(i,N){
//       while(j<N && m<k){
//         if((cnt[S[j]]++)==0) m++;
//         j++;
//       }
//       if(j==N && m<k) break;
//       res += N-j+1;
//       if((--cnt[S[i]])==0) m--;
//     }
//   }
// 
//   res /= (double)N*(N+1)/2;
// 
//   wt(res);
// }
0