結果

問題 No.852 連続部分文字列
ユーザー tentententen
提出日時 2023-01-10 13:40:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 343 ms / 3,153 ms
コード長 2,223 bytes
コンパイル時間 2,538 ms
コンパイル使用メモリ 94,392 KB
実行使用メモリ 80,844 KB
最終ジャッジ日時 2023-08-23 10:13:28
合計ジャッジ時間 10,922 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,548 KB
testcase_01 AC 42 ms
49,548 KB
testcase_02 AC 43 ms
49,512 KB
testcase_03 AC 43 ms
49,380 KB
testcase_04 AC 44 ms
49,376 KB
testcase_05 AC 42 ms
49,468 KB
testcase_06 AC 43 ms
49,444 KB
testcase_07 AC 43 ms
49,572 KB
testcase_08 AC 43 ms
49,808 KB
testcase_09 AC 43 ms
49,500 KB
testcase_10 AC 43 ms
49,756 KB
testcase_11 AC 43 ms
49,428 KB
testcase_12 AC 43 ms
49,588 KB
testcase_13 AC 78 ms
50,572 KB
testcase_14 AC 59 ms
50,932 KB
testcase_15 AC 74 ms
51,048 KB
testcase_16 AC 79 ms
52,144 KB
testcase_17 AC 73 ms
51,396 KB
testcase_18 AC 74 ms
50,388 KB
testcase_19 AC 51 ms
49,760 KB
testcase_20 AC 77 ms
50,412 KB
testcase_21 AC 81 ms
52,180 KB
testcase_22 AC 64 ms
50,536 KB
testcase_23 AC 70 ms
50,708 KB
testcase_24 AC 63 ms
50,608 KB
testcase_25 AC 71 ms
50,928 KB
testcase_26 AC 74 ms
50,376 KB
testcase_27 AC 78 ms
50,884 KB
testcase_28 AC 74 ms
50,728 KB
testcase_29 AC 83 ms
51,956 KB
testcase_30 AC 54 ms
49,692 KB
testcase_31 AC 80 ms
51,772 KB
testcase_32 AC 80 ms
51,484 KB
testcase_33 AC 343 ms
80,352 KB
testcase_34 AC 337 ms
78,680 KB
testcase_35 AC 331 ms
80,392 KB
testcase_36 AC 338 ms
80,844 KB
testcase_37 AC 338 ms
80,428 KB
testcase_38 AC 339 ms
80,244 KB
testcase_39 AC 335 ms
78,964 KB
testcase_40 AC 336 ms
80,700 KB
testcase_41 AC 334 ms
80,672 KB
testcase_42 AC 328 ms
79,132 KB
testcase_43 AC 331 ms
77,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] inputs = sc.next().toCharArray();
        int length = inputs.length;
        HashMap<Character, ArrayList<Integer>> mapping = new HashMap<>();
        for (int i = 0; i < length; i++) {
            if (!mapping.containsKey(inputs[i])) {
                mapping.put(inputs[i], new ArrayList<>());
            }
            mapping.get(inputs[i]).add(i);
        }
        double total = 0;
        for (ArrayList<Integer> list : mapping.values()) {
            total += (long)length * (length + 1) / 2;
            list.add(length);
            int prev = -1;
            for (int x : list) {
                long tmp = x - prev - 1;
                total -= tmp * (tmp + 1) / 2;
                prev = x;
            }
        }
        System.out.println(total / length / (length + 1) * 2);
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0