結果

問題 No.852 連続部分文字列
ユーザー htensaihtensai
提出日時 2020-02-14 12:47:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 464 ms / 3,153 ms
コード長 814 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 76,640 KB
実行使用メモリ 85,208 KB
最終ジャッジ日時 2024-04-16 00:14:58
合計ジャッジ時間 14,862 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
54,156 KB
testcase_01 AC 131 ms
53,808 KB
testcase_02 AC 131 ms
54,112 KB
testcase_03 AC 129 ms
53,860 KB
testcase_04 AC 131 ms
54,152 KB
testcase_05 AC 131 ms
54,240 KB
testcase_06 AC 131 ms
54,192 KB
testcase_07 AC 130 ms
54,076 KB
testcase_08 AC 131 ms
54,136 KB
testcase_09 AC 129 ms
54,108 KB
testcase_10 AC 130 ms
54,212 KB
testcase_11 AC 137 ms
54,076 KB
testcase_12 AC 133 ms
53,868 KB
testcase_13 AC 163 ms
53,900 KB
testcase_14 AC 154 ms
54,196 KB
testcase_15 AC 171 ms
54,360 KB
testcase_16 AC 162 ms
54,380 KB
testcase_17 AC 168 ms
54,268 KB
testcase_18 AC 173 ms
54,088 KB
testcase_19 AC 139 ms
54,144 KB
testcase_20 AC 171 ms
54,288 KB
testcase_21 AC 174 ms
54,364 KB
testcase_22 AC 164 ms
54,212 KB
testcase_23 AC 166 ms
54,076 KB
testcase_24 AC 159 ms
54,500 KB
testcase_25 AC 164 ms
54,112 KB
testcase_26 AC 172 ms
53,852 KB
testcase_27 AC 163 ms
53,960 KB
testcase_28 AC 164 ms
54,320 KB
testcase_29 AC 177 ms
54,312 KB
testcase_30 AC 149 ms
54,160 KB
testcase_31 AC 173 ms
54,504 KB
testcase_32 AC 175 ms
56,024 KB
testcase_33 AC 463 ms
84,668 KB
testcase_34 AC 464 ms
85,020 KB
testcase_35 AC 459 ms
84,876 KB
testcase_36 AC 450 ms
84,960 KB
testcase_37 AC 453 ms
85,048 KB
testcase_38 AC 459 ms
85,208 KB
testcase_39 AC 460 ms
85,012 KB
testcase_40 AC 452 ms
84,736 KB
testcase_41 AC 463 ms
85,148 KB
testcase_42 AC 455 ms
84,888 KB
testcase_43 AC 443 ms
82,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		long length = arr.length;
		HashMap<Character, ArrayList<Integer>> map = new HashMap<>();
		for (int i = 'a'; i <= 'z'; i++) {
		    map.put((char)i, new ArrayList<Integer>());
		}
		for (int i = 0; i < length; i++) {
		    map.get(arr[i]).add(i);
		}
		long sum = 0;
		for (ArrayList<Integer> list : map.values()) {
		    int start = 0;
		    for (int x : list) {
		        long size = x - start;
		        sum += size * (size + 1) / 2;
		        start = x + 1;
		    }
		    long size = length - start;
		    sum += size * (size + 1) / 2;
		}
		System.out.println((26 * length * (length + 1) / 2 - (double)sum) / length / (length + 1) * 2);
  }
}
0