結果
問題 | No.852 連続部分文字列 |
ユーザー | tenten |
提出日時 | 2023-01-10 13:40:25 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 347 ms / 3,153 ms |
コード長 | 2,223 bytes |
コンパイル時間 | 2,686 ms |
コンパイル使用メモリ | 92,476 KB |
実行使用メモリ | 80,420 KB |
最終ジャッジ日時 | 2024-12-21 12:13:16 |
合計ジャッジ時間 | 11,148 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
50,104 KB |
testcase_01 | AC | 53 ms
50,136 KB |
testcase_02 | AC | 52 ms
50,180 KB |
testcase_03 | AC | 52 ms
50,432 KB |
testcase_04 | AC | 52 ms
50,260 KB |
testcase_05 | AC | 53 ms
50,356 KB |
testcase_06 | AC | 54 ms
50,272 KB |
testcase_07 | AC | 53 ms
50,000 KB |
testcase_08 | AC | 52 ms
50,224 KB |
testcase_09 | AC | 55 ms
49,976 KB |
testcase_10 | AC | 52 ms
50,164 KB |
testcase_11 | AC | 53 ms
50,460 KB |
testcase_12 | AC | 51 ms
50,324 KB |
testcase_13 | AC | 83 ms
50,852 KB |
testcase_14 | AC | 62 ms
50,780 KB |
testcase_15 | AC | 89 ms
51,076 KB |
testcase_16 | AC | 83 ms
50,776 KB |
testcase_17 | AC | 88 ms
51,116 KB |
testcase_18 | AC | 81 ms
51,260 KB |
testcase_19 | AC | 54 ms
50,152 KB |
testcase_20 | AC | 82 ms
50,940 KB |
testcase_21 | AC | 88 ms
51,836 KB |
testcase_22 | AC | 80 ms
51,072 KB |
testcase_23 | AC | 78 ms
51,240 KB |
testcase_24 | AC | 81 ms
51,008 KB |
testcase_25 | AC | 85 ms
50,900 KB |
testcase_26 | AC | 82 ms
50,912 KB |
testcase_27 | AC | 85 ms
51,088 KB |
testcase_28 | AC | 79 ms
51,116 KB |
testcase_29 | AC | 89 ms
51,720 KB |
testcase_30 | AC | 57 ms
50,340 KB |
testcase_31 | AC | 86 ms
51,528 KB |
testcase_32 | AC | 87 ms
51,800 KB |
testcase_33 | AC | 330 ms
79,984 KB |
testcase_34 | AC | 323 ms
77,896 KB |
testcase_35 | AC | 325 ms
79,668 KB |
testcase_36 | AC | 330 ms
80,420 KB |
testcase_37 | AC | 316 ms
80,108 KB |
testcase_38 | AC | 325 ms
80,184 KB |
testcase_39 | AC | 338 ms
78,080 KB |
testcase_40 | AC | 341 ms
79,900 KB |
testcase_41 | AC | 347 ms
78,172 KB |
testcase_42 | AC | 332 ms
78,600 KB |
testcase_43 | AC | 324 ms
77,248 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(); int length = inputs.length; HashMap<Character, ArrayList<Integer>> mapping = new HashMap<>(); for (int i = 0; i < length; i++) { if (!mapping.containsKey(inputs[i])) { mapping.put(inputs[i], new ArrayList<>()); } mapping.get(inputs[i]).add(i); } double total = 0; for (ArrayList<Integer> list : mapping.values()) { total += (long)length * (length + 1) / 2; list.add(length); int prev = -1; for (int x : list) { long tmp = x - prev - 1; total -= tmp * (tmp + 1) / 2; prev = x; } } System.out.println(total / length / (length + 1) * 2); } } 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(); } }