結果

問題 No.852 連続部分文字列
ユーザー tentententen
提出日時 2023-11-16 09:03:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 283 ms / 3,153 ms
コード長 2,057 bytes
コンパイル時間 2,880 ms
コンパイル使用メモリ 89,704 KB
実行使用メモリ 59,616 KB
最終ジャッジ日時 2023-11-16 09:04:03
合計ジャッジ時間 10,981 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
54,516 KB
testcase_01 AC 57 ms
54,504 KB
testcase_02 AC 57 ms
54,508 KB
testcase_03 AC 58 ms
54,508 KB
testcase_04 AC 56 ms
54,504 KB
testcase_05 AC 56 ms
54,500 KB
testcase_06 AC 56 ms
54,516 KB
testcase_07 AC 57 ms
54,504 KB
testcase_08 AC 58 ms
54,512 KB
testcase_09 AC 58 ms
54,512 KB
testcase_10 AC 60 ms
54,492 KB
testcase_11 AC 56 ms
54,504 KB
testcase_12 AC 57 ms
54,508 KB
testcase_13 AC 74 ms
55,532 KB
testcase_14 AC 66 ms
54,772 KB
testcase_15 AC 79 ms
53,576 KB
testcase_16 AC 74 ms
55,420 KB
testcase_17 AC 78 ms
55,408 KB
testcase_18 AC 77 ms
55,548 KB
testcase_19 AC 59 ms
54,508 KB
testcase_20 AC 71 ms
54,648 KB
testcase_21 AC 79 ms
55,536 KB
testcase_22 AC 67 ms
54,684 KB
testcase_23 AC 78 ms
55,516 KB
testcase_24 AC 68 ms
54,640 KB
testcase_25 AC 74 ms
54,876 KB
testcase_26 AC 80 ms
55,544 KB
testcase_27 AC 74 ms
55,408 KB
testcase_28 AC 77 ms
55,400 KB
testcase_29 AC 81 ms
55,492 KB
testcase_30 AC 63 ms
54,508 KB
testcase_31 AC 79 ms
55,552 KB
testcase_32 AC 80 ms
55,528 KB
testcase_33 AC 278 ms
59,324 KB
testcase_34 AC 280 ms
59,616 KB
testcase_35 AC 264 ms
59,340 KB
testcase_36 AC 276 ms
59,296 KB
testcase_37 AC 271 ms
59,540 KB
testcase_38 AC 276 ms
59,388 KB
testcase_39 AC 283 ms
57,396 KB
testcase_40 AC 271 ms
59,316 KB
testcase_41 AC 277 ms
59,352 KB
testcase_42 AC 283 ms
59,280 KB
testcase_43 AC 272 ms
59,484 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;
        double total = 26 * (length + 1L) * length / 2;
        for (char c = 'a'; c <= 'z'; c = (char)(c + 1)) {
            int count = 0;
            for (char x : inputs) {
                if (c == x) {
                    total -= (count + 1L) * count / 2;
                    count = 0;
                } else {
                    count++;
                }
            }
            total -= (count + 1L) * count / 2;
        }
        total /= (length + 1L) * length / 2;
        System.out.println(new java.math.BigDecimal(total).toPlainString());
    }
}
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