結果
問題 | No.852 連続部分文字列 |
ユーザー | tenten |
提出日時 | 2023-01-10 13:40:25 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 376 ms / 3,153 ms |
コード長 | 2,223 bytes |
コンパイル時間 | 3,170 ms |
コンパイル使用メモリ | 92,024 KB |
実行使用メモリ | 80,216 KB |
最終ジャッジ日時 | 2024-06-01 07:51:27 |
合計ジャッジ時間 | 11,855 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
50,412 KB |
testcase_01 | AC | 59 ms
50,372 KB |
testcase_02 | AC | 58 ms
50,336 KB |
testcase_03 | AC | 57 ms
50,596 KB |
testcase_04 | AC | 58 ms
50,600 KB |
testcase_05 | AC | 59 ms
50,564 KB |
testcase_06 | AC | 58 ms
50,404 KB |
testcase_07 | AC | 59 ms
50,216 KB |
testcase_08 | AC | 58 ms
50,692 KB |
testcase_09 | AC | 59 ms
50,460 KB |
testcase_10 | AC | 58 ms
50,132 KB |
testcase_11 | AC | 58 ms
50,724 KB |
testcase_12 | AC | 58 ms
50,512 KB |
testcase_13 | AC | 91 ms
51,304 KB |
testcase_14 | AC | 83 ms
51,220 KB |
testcase_15 | AC | 101 ms
51,032 KB |
testcase_16 | AC | 93 ms
51,288 KB |
testcase_17 | AC | 90 ms
51,404 KB |
testcase_18 | AC | 92 ms
51,316 KB |
testcase_19 | AC | 60 ms
50,468 KB |
testcase_20 | AC | 89 ms
51,072 KB |
testcase_21 | AC | 98 ms
52,112 KB |
testcase_22 | AC | 89 ms
50,876 KB |
testcase_23 | AC | 93 ms
51,380 KB |
testcase_24 | AC | 86 ms
51,184 KB |
testcase_25 | AC | 95 ms
51,328 KB |
testcase_26 | AC | 93 ms
51,300 KB |
testcase_27 | AC | 94 ms
51,500 KB |
testcase_28 | AC | 101 ms
51,308 KB |
testcase_29 | AC | 97 ms
52,172 KB |
testcase_30 | AC | 68 ms
50,484 KB |
testcase_31 | AC | 97 ms
52,000 KB |
testcase_32 | AC | 97 ms
52,208 KB |
testcase_33 | AC | 365 ms
80,216 KB |
testcase_34 | AC | 364 ms
78,232 KB |
testcase_35 | AC | 365 ms
79,640 KB |
testcase_36 | AC | 367 ms
80,204 KB |
testcase_37 | AC | 373 ms
80,056 KB |
testcase_38 | AC | 376 ms
80,096 KB |
testcase_39 | AC | 367 ms
77,996 KB |
testcase_40 | AC | 366 ms
80,060 KB |
testcase_41 | AC | 364 ms
78,296 KB |
testcase_42 | AC | 361 ms
78,196 KB |
testcase_43 | AC | 362 ms
77,168 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(); } }