結果
問題 | No.852 連続部分文字列 |
ユーザー | tenten |
提出日時 | 2023-07-07 17:43:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 810 ms / 3,153 ms |
コード長 | 2,179 bytes |
コンパイル時間 | 4,527 ms |
コンパイル使用メモリ | 93,900 KB |
実行使用メモリ | 120,460 KB |
最終ジャッジ日時 | 2023-09-28 18:27:55 |
合計ジャッジ時間 | 18,226 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
50,396 KB |
testcase_01 | AC | 49 ms
50,124 KB |
testcase_02 | AC | 49 ms
49,984 KB |
testcase_03 | AC | 48 ms
50,032 KB |
testcase_04 | AC | 47 ms
50,040 KB |
testcase_05 | AC | 48 ms
50,052 KB |
testcase_06 | AC | 47 ms
49,924 KB |
testcase_07 | AC | 48 ms
50,052 KB |
testcase_08 | AC | 50 ms
50,092 KB |
testcase_09 | AC | 48 ms
50,264 KB |
testcase_10 | AC | 48 ms
50,524 KB |
testcase_11 | AC | 48 ms
50,084 KB |
testcase_12 | AC | 49 ms
50,056 KB |
testcase_13 | AC | 104 ms
53,760 KB |
testcase_14 | AC | 83 ms
53,428 KB |
testcase_15 | AC | 126 ms
53,480 KB |
testcase_16 | AC | 109 ms
53,680 KB |
testcase_17 | AC | 121 ms
53,576 KB |
testcase_18 | AC | 127 ms
55,668 KB |
testcase_19 | AC | 62 ms
51,732 KB |
testcase_20 | AC | 103 ms
53,296 KB |
testcase_21 | AC | 134 ms
56,112 KB |
testcase_22 | AC | 91 ms
53,460 KB |
testcase_23 | AC | 111 ms
53,420 KB |
testcase_24 | AC | 102 ms
53,900 KB |
testcase_25 | AC | 111 ms
53,472 KB |
testcase_26 | AC | 125 ms
53,124 KB |
testcase_27 | AC | 99 ms
51,508 KB |
testcase_28 | AC | 120 ms
53,344 KB |
testcase_29 | AC | 133 ms
56,364 KB |
testcase_30 | AC | 87 ms
53,412 KB |
testcase_31 | AC | 128 ms
55,884 KB |
testcase_32 | AC | 127 ms
55,584 KB |
testcase_33 | AC | 803 ms
120,396 KB |
testcase_34 | AC | 801 ms
120,208 KB |
testcase_35 | AC | 809 ms
120,364 KB |
testcase_36 | AC | 805 ms
120,292 KB |
testcase_37 | AC | 793 ms
118,280 KB |
testcase_38 | AC | 805 ms
120,460 KB |
testcase_39 | AC | 810 ms
120,404 KB |
testcase_40 | AC | 806 ms
120,164 KB |
testcase_41 | AC | 808 ms
120,280 KB |
testcase_42 | AC | 739 ms
120,104 KB |
testcase_43 | AC | 769 ms
120,232 KB |
ソースコード
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 + 1); } for (int i = 0; i < inputs.length; i++) { places.get(inputs[i] - 'a').add(i + 1); } double all = (double)inputs.length * (inputs.length + 1) / 2; double total = all * 26; for (TreeSet<Integer> org : places) { int prev = 0; for (int x : org) { total -= (x - prev) * (x - prev - 1.0) / 2; prev = x; } } System.out.println(new java.math.BigDecimal(total / all).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(); } }