結果

問題 No.852 連続部分文字列
ユーザー tentententen
提出日時 2023-04-24 17:21:43
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,184 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 85,996 KB
実行使用メモリ 120,888 KB
最終ジャッジ日時 2024-04-26 05:29:03
合計ジャッジ時間 15,844 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
50,476 KB
testcase_01 AC 53 ms
50,440 KB
testcase_02 AC 55 ms
50,516 KB
testcase_03 AC 53 ms
50,528 KB
testcase_04 AC 52 ms
50,056 KB
testcase_05 AC 52 ms
50,472 KB
testcase_06 AC 52 ms
50,200 KB
testcase_07 AC 52 ms
50,560 KB
testcase_08 AC 54 ms
50,260 KB
testcase_09 AC 53 ms
50,456 KB
testcase_10 AC 52 ms
50,108 KB
testcase_11 AC 54 ms
50,160 KB
testcase_12 AC 55 ms
50,452 KB
testcase_13 AC 112 ms
52,628 KB
testcase_14 AC 99 ms
52,752 KB
testcase_15 AC 115 ms
52,556 KB
testcase_16 AC 113 ms
52,548 KB
testcase_17 AC 112 ms
52,692 KB
testcase_18 AC 127 ms
52,724 KB
testcase_19 AC 64 ms
50,880 KB
testcase_20 AC 108 ms
52,540 KB
testcase_21 AC 138 ms
54,876 KB
testcase_22 AC 101 ms
52,684 KB
testcase_23 AC 110 ms
52,452 KB
testcase_24 AC 104 ms
52,428 KB
testcase_25 AC 118 ms
52,476 KB
testcase_26 AC 116 ms
52,756 KB
testcase_27 AC 117 ms
52,740 KB
testcase_28 AC 123 ms
52,768 KB
testcase_29 AC 120 ms
54,828 KB
testcase_30 AC 92 ms
52,120 KB
testcase_31 AC 133 ms
54,604 KB
testcase_32 AC 132 ms
54,668 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

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 + 1) / 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