結果

問題 No.852 連続部分文字列
ユーザー tentententen
提出日時 2023-03-15 11:55:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 870 ms / 3,153 ms
コード長 2,209 bytes
コンパイル時間 2,693 ms
コンパイル使用メモリ 85,472 KB
実行使用メモリ 122,512 KB
最終ジャッジ日時 2023-10-18 12:18:44
合計ジャッジ時間 17,354 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
53,592 KB
testcase_01 AC 55 ms
53,600 KB
testcase_02 AC 57 ms
53,608 KB
testcase_03 AC 56 ms
52,556 KB
testcase_04 AC 56 ms
53,608 KB
testcase_05 AC 56 ms
53,592 KB
testcase_06 AC 55 ms
53,592 KB
testcase_07 AC 57 ms
53,596 KB
testcase_08 AC 55 ms
53,592 KB
testcase_09 AC 56 ms
53,592 KB
testcase_10 AC 55 ms
53,592 KB
testcase_11 AC 57 ms
53,600 KB
testcase_12 AC 57 ms
53,592 KB
testcase_13 AC 114 ms
55,816 KB
testcase_14 AC 99 ms
55,520 KB
testcase_15 AC 128 ms
55,964 KB
testcase_16 AC 115 ms
55,988 KB
testcase_17 AC 125 ms
56,008 KB
testcase_18 AC 128 ms
55,964 KB
testcase_19 AC 68 ms
54,976 KB
testcase_20 AC 108 ms
55,900 KB
testcase_21 AC 137 ms
58,028 KB
testcase_22 AC 105 ms
55,860 KB
testcase_23 AC 119 ms
56,044 KB
testcase_24 AC 105 ms
55,980 KB
testcase_25 AC 113 ms
55,888 KB
testcase_26 AC 121 ms
55,836 KB
testcase_27 AC 121 ms
55,900 KB
testcase_28 AC 127 ms
53,904 KB
testcase_29 AC 139 ms
58,020 KB
testcase_30 AC 98 ms
55,324 KB
testcase_31 AC 137 ms
58,196 KB
testcase_32 AC 144 ms
58,160 KB
testcase_33 AC 852 ms
122,500 KB
testcase_34 AC 858 ms
122,464 KB
testcase_35 AC 844 ms
122,512 KB
testcase_36 AC 841 ms
122,448 KB
testcase_37 AC 842 ms
122,488 KB
testcase_38 AC 831 ms
122,472 KB
testcase_39 AC 851 ms
122,168 KB
testcase_40 AC 870 ms
122,184 KB
testcase_41 AC 853 ms
122,308 KB
testcase_42 AC 761 ms
122,200 KB
testcase_43 AC 814 ms
122,152 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;
        ArrayList<TreeSet<Integer>> places = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            places.add(new TreeSet<>());
            places.get(i).add(length);
        }
        for (int i = 0; i < length; i++) {
            places.get(inputs[i] - 'a').add(i);
        }
        double ans = 0;
        for (TreeSet<Integer> current : places) {
            int prev = -1;
            for (int x : current) {
                long distance = x - prev - 1;
                ans += distance * (distance + 1) / 2;
                prev = x;
            }
            
        }
        long all = length * (length + 1L) / 2;
        ans = all * 26 - ans;
        System.out.println(ans / all);
    }
}
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