結果

問題 No.852 連続部分文字列
ユーザー tentententen
提出日時 2023-04-24 17:23:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 848 ms / 3,153 ms
コード長 2,185 bytes
コンパイル時間 2,843 ms
コンパイル使用メモリ 85,740 KB
実行使用メモリ 106,444 KB
最終ジャッジ日時 2024-04-26 05:31:02
合計ジャッジ時間 16,764 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
37,280 KB
testcase_01 AC 57 ms
37,332 KB
testcase_02 AC 56 ms
37,308 KB
testcase_03 AC 59 ms
37,380 KB
testcase_04 AC 57 ms
37,320 KB
testcase_05 AC 54 ms
37,092 KB
testcase_06 AC 54 ms
37,264 KB
testcase_07 AC 54 ms
36,976 KB
testcase_08 AC 55 ms
37,092 KB
testcase_09 AC 55 ms
37,160 KB
testcase_10 AC 56 ms
37,368 KB
testcase_11 AC 59 ms
37,528 KB
testcase_12 AC 53 ms
37,304 KB
testcase_13 AC 115 ms
40,600 KB
testcase_14 AC 100 ms
39,704 KB
testcase_15 AC 122 ms
41,852 KB
testcase_16 AC 113 ms
40,460 KB
testcase_17 AC 118 ms
40,852 KB
testcase_18 AC 135 ms
41,248 KB
testcase_19 AC 64 ms
37,844 KB
testcase_20 AC 109 ms
40,628 KB
testcase_21 AC 142 ms
41,492 KB
testcase_22 AC 106 ms
39,732 KB
testcase_23 AC 122 ms
40,576 KB
testcase_24 AC 107 ms
40,044 KB
testcase_25 AC 121 ms
40,660 KB
testcase_26 AC 123 ms
41,116 KB
testcase_27 AC 121 ms
40,292 KB
testcase_28 AC 126 ms
40,820 KB
testcase_29 AC 136 ms
41,000 KB
testcase_30 AC 95 ms
39,364 KB
testcase_31 AC 143 ms
41,284 KB
testcase_32 AC 142 ms
41,156 KB
testcase_33 AC 848 ms
106,300 KB
testcase_34 AC 829 ms
106,236 KB
testcase_35 AC 836 ms
106,152 KB
testcase_36 AC 828 ms
106,336 KB
testcase_37 AC 811 ms
106,424 KB
testcase_38 AC 831 ms
106,036 KB
testcase_39 AC 845 ms
106,444 KB
testcase_40 AC 839 ms
105,948 KB
testcase_41 AC 827 ms
106,120 KB
testcase_42 AC 792 ms
106,044 KB
testcase_43 AC 796 ms
105,988 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();
        ArrayList<TreeSet<Integer>> places = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            places.add(new TreeSet<>());
            places.get(i).add(inputs.length);
        }
        for (int i = 0; i < inputs.length; i++) {
            places.get(inputs[i] - 'a').add(i);
        }
        double total = 26.0 * inputs.length * (inputs.length + 1) / 2;
        for (TreeSet<Integer> tmp : places) {
            int prev = -1;
            for (int x : tmp) {
                long count = x - prev - 1;
                total -= count * (count + 1) / 2;
                prev = x;
            }
        }
        total /= inputs.length * (inputs.length + 1L) / 2;
        System.out.println(total);

    }
}
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