結果

問題 No.852 連続部分文字列
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-05 23:14:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 337 ms / 3,153 ms
コード長 767 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 74,520 KB
実行使用メモリ 76,516 KB
最終ジャッジ日時 2023-09-04 15:01:08
合計ジャッジ時間 12,369 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,768 KB
testcase_01 AC 118 ms
55,288 KB
testcase_02 AC 121 ms
55,988 KB
testcase_03 AC 119 ms
53,836 KB
testcase_04 AC 120 ms
55,540 KB
testcase_05 AC 120 ms
55,756 KB
testcase_06 AC 119 ms
55,624 KB
testcase_07 AC 121 ms
55,780 KB
testcase_08 AC 119 ms
55,420 KB
testcase_09 AC 123 ms
55,380 KB
testcase_10 AC 121 ms
55,804 KB
testcase_11 AC 120 ms
55,940 KB
testcase_12 AC 124 ms
55,268 KB
testcase_13 AC 141 ms
55,612 KB
testcase_14 AC 140 ms
55,744 KB
testcase_15 AC 148 ms
55,512 KB
testcase_16 AC 142 ms
55,352 KB
testcase_17 AC 145 ms
56,084 KB
testcase_18 AC 148 ms
55,664 KB
testcase_19 AC 126 ms
55,960 KB
testcase_20 AC 139 ms
55,764 KB
testcase_21 AC 152 ms
55,808 KB
testcase_22 AC 137 ms
55,808 KB
testcase_23 AC 144 ms
55,804 KB
testcase_24 AC 136 ms
55,696 KB
testcase_25 AC 141 ms
55,732 KB
testcase_26 AC 145 ms
55,772 KB
testcase_27 AC 138 ms
55,560 KB
testcase_28 AC 142 ms
56,056 KB
testcase_29 AC 147 ms
55,936 KB
testcase_30 AC 134 ms
55,840 KB
testcase_31 AC 155 ms
55,432 KB
testcase_32 AC 150 ms
55,880 KB
testcase_33 AC 335 ms
76,484 KB
testcase_34 AC 327 ms
76,092 KB
testcase_35 AC 333 ms
76,048 KB
testcase_36 AC 328 ms
76,360 KB
testcase_37 AC 337 ms
76,088 KB
testcase_38 AC 318 ms
74,724 KB
testcase_39 AC 317 ms
76,208 KB
testcase_40 AC 316 ms
76,092 KB
testcase_41 AC 321 ms
76,160 KB
testcase_42 AC 322 ms
76,232 KB
testcase_43 AC 322 ms
76,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    long[] use = new long[26];
    for(int i = 0; i < 26; i++) {
      use[i] = -1;
    }
    long[] dis = new long[s.length()];
    for(int i = 0; i < s.length(); i++) {
      int t = s.charAt(i) - 97;
      dis[i] = i - use[t];
      use[t] = i;
    }
    long[] dp = new long[s.length()];
    dp[0] = 1;
    for(int i = 1; i < s.length(); i++) {
      dp[i] = dp[i - 1] + dis[i];
    }
    long sa = s.length();
    long a = (sa * (sa - 1)) / 2 + sa;
    long sum = 0;
    for(int i = 0; i < s.length(); i++) {
      sum += dp[i];
    }
    double ans = (double)sum / (double)a;
    System.out.println(ans);
  }
}
0