結果
問題 | No.852 連続部分文字列 |
ユーザー | tenten |
提出日時 | 2021-11-04 09:23:12 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 862 ms / 3,153 ms |
コード長 | 1,741 bytes |
コンパイル時間 | 2,926 ms |
コンパイル使用メモリ | 79,384 KB |
実行使用メモリ | 107,204 KB |
最終ジャッジ日時 | 2024-04-22 06:40:12 |
合計ジャッジ時間 | 17,679 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
36,960 KB |
testcase_01 | AC | 57 ms
36,972 KB |
testcase_02 | AC | 58 ms
37,140 KB |
testcase_03 | AC | 57 ms
36,928 KB |
testcase_04 | AC | 57 ms
37,084 KB |
testcase_05 | AC | 56 ms
36,700 KB |
testcase_06 | AC | 57 ms
37,084 KB |
testcase_07 | AC | 57 ms
37,196 KB |
testcase_08 | AC | 59 ms
36,688 KB |
testcase_09 | AC | 58 ms
37,116 KB |
testcase_10 | AC | 57 ms
37,180 KB |
testcase_11 | AC | 57 ms
37,092 KB |
testcase_12 | AC | 57 ms
37,228 KB |
testcase_13 | AC | 118 ms
40,448 KB |
testcase_14 | AC | 102 ms
39,440 KB |
testcase_15 | AC | 131 ms
41,012 KB |
testcase_16 | AC | 120 ms
40,468 KB |
testcase_17 | AC | 127 ms
40,780 KB |
testcase_18 | AC | 134 ms
41,016 KB |
testcase_19 | AC | 76 ms
37,964 KB |
testcase_20 | AC | 110 ms
39,752 KB |
testcase_21 | AC | 140 ms
41,108 KB |
testcase_22 | AC | 100 ms
39,660 KB |
testcase_23 | AC | 115 ms
40,504 KB |
testcase_24 | AC | 107 ms
39,624 KB |
testcase_25 | AC | 122 ms
40,480 KB |
testcase_26 | AC | 134 ms
40,856 KB |
testcase_27 | AC | 123 ms
40,380 KB |
testcase_28 | AC | 125 ms
40,400 KB |
testcase_29 | AC | 131 ms
40,892 KB |
testcase_30 | AC | 101 ms
38,880 KB |
testcase_31 | AC | 152 ms
41,252 KB |
testcase_32 | AC | 151 ms
41,920 KB |
testcase_33 | AC | 831 ms
106,004 KB |
testcase_34 | AC | 830 ms
106,084 KB |
testcase_35 | AC | 829 ms
106,288 KB |
testcase_36 | AC | 825 ms
106,000 KB |
testcase_37 | AC | 834 ms
106,120 KB |
testcase_38 | AC | 841 ms
105,988 KB |
testcase_39 | AC | 855 ms
107,124 KB |
testcase_40 | AC | 862 ms
106,056 KB |
testcase_41 | AC | 829 ms
106,756 KB |
testcase_42 | AC | 746 ms
106,188 KB |
testcase_43 | AC | 784 ms
107,204 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static int n; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); char[] values = sc.next().toCharArray(); int length = values.length; ArrayList<TreeSet<Integer>> alpha = new ArrayList<>(); for (int i = 0; i < 26; i++) { alpha.add(new TreeSet<>()); alpha.get(i).add(length + 1); } for (int i = 0; i < length; i++) { alpha.get(values[i] - 'a').add(i + 1); } long count = 0; long base = (long)length * (length + 1) / 2; for (TreeSet<Integer> set : alpha) { int prev = 0; long tmp = 0; for (int x : set) { tmp += (long)(x - prev - 1) * (x - prev) / 2; prev = x; } count += base - tmp; } System.out.println((double)count / base); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }