結果

問題 No.852 連続部分文字列
ユーザー tentententen
提出日時 2020-08-31 17:56:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 543 ms / 3,153 ms
コード長 1,012 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 79,908 KB
実行使用メモリ 73,824 KB
最終ジャッジ日時 2024-04-28 05:52:07
合計ジャッジ時間 15,891 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
41,132 KB
testcase_01 AC 126 ms
41,036 KB
testcase_02 AC 126 ms
41,232 KB
testcase_03 AC 124 ms
41,028 KB
testcase_04 AC 125 ms
41,208 KB
testcase_05 AC 128 ms
41,304 KB
testcase_06 AC 126 ms
41,172 KB
testcase_07 AC 126 ms
41,152 KB
testcase_08 AC 114 ms
40,200 KB
testcase_09 AC 131 ms
41,284 KB
testcase_10 AC 124 ms
40,988 KB
testcase_11 AC 129 ms
41,176 KB
testcase_12 AC 129 ms
41,232 KB
testcase_13 AC 178 ms
41,968 KB
testcase_14 AC 158 ms
41,524 KB
testcase_15 AC 188 ms
42,656 KB
testcase_16 AC 178 ms
41,908 KB
testcase_17 AC 185 ms
42,144 KB
testcase_18 AC 193 ms
42,648 KB
testcase_19 AC 138 ms
41,316 KB
testcase_20 AC 175 ms
42,028 KB
testcase_21 AC 191 ms
42,664 KB
testcase_22 AC 171 ms
41,932 KB
testcase_23 AC 163 ms
42,320 KB
testcase_24 AC 176 ms
42,276 KB
testcase_25 AC 187 ms
42,440 KB
testcase_26 AC 183 ms
42,740 KB
testcase_27 AC 187 ms
42,476 KB
testcase_28 AC 182 ms
42,572 KB
testcase_29 AC 189 ms
42,836 KB
testcase_30 AC 162 ms
41,384 KB
testcase_31 AC 189 ms
42,720 KB
testcase_32 AC 191 ms
42,964 KB
testcase_33 AC 531 ms
73,824 KB
testcase_34 AC 542 ms
73,676 KB
testcase_35 AC 532 ms
73,752 KB
testcase_36 AC 525 ms
73,740 KB
testcase_37 AC 542 ms
73,432 KB
testcase_38 AC 543 ms
73,468 KB
testcase_39 AC 534 ms
73,732 KB
testcase_40 AC 506 ms
73,584 KB
testcase_41 AC 530 ms
73,812 KB
testcase_42 AC 523 ms
73,208 KB
testcase_43 AC 510 ms
72,292 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();
    	int length = arr.length;
    	HashMap<Integer, ArrayList<Integer>> charPlace = new HashMap<>();
    	for (int i = 0; i < 26; i++) {
    	    charPlace.put(i, new ArrayList<>());
    	}
    	for (int i = 0; i < length; i++) {
    	    charPlace.get(arr[i] - 'a').add(i);
    	}
    	int[] idxes = new int[26];
    	int[] places = new int[26];
    	for (int i = 0; i < 26; i++) {
    	    charPlace.get(i).add(length);
    	    places[i] = charPlace.get(i).get(0);
    	}
    	double total = 0;
    	for (int i = 0; i < length; i++) {
    	    for (int j = 0; j < 26; j++) {
    	        total += length - places[j];
    	    }
    	    int idx = arr[i] - 'a';
    	    idxes[idx]++;
    	    places[idx] = charPlace.get(idx).get(idxes[idx]);
    	}
    	double ans = total / length / (length + 1) * 2;
    	System.out.println(ans);
    }
}
0