結果
問題 | No.2715 Unique Chimatagram |
ユーザー | tenten |
提出日時 | 2024-04-08 10:05:44 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 150 ms / 2,000 ms |
コード長 | 2,581 bytes |
コンパイル時間 | 2,260 ms |
コンパイル使用メモリ | 79,616 KB |
実行使用メモリ | 46,056 KB |
最終ジャッジ日時 | 2024-10-01 05:02:05 |
合計ジャッジ時間 | 8,476 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
36,964 KB |
testcase_01 | AC | 51 ms
36,968 KB |
testcase_02 | AC | 50 ms
37,160 KB |
testcase_03 | AC | 52 ms
36,972 KB |
testcase_04 | AC | 50 ms
36,952 KB |
testcase_05 | AC | 53 ms
37,048 KB |
testcase_06 | AC | 50 ms
36,952 KB |
testcase_07 | AC | 49 ms
37,036 KB |
testcase_08 | AC | 136 ms
45,064 KB |
testcase_09 | AC | 138 ms
45,716 KB |
testcase_10 | AC | 139 ms
45,376 KB |
testcase_11 | AC | 136 ms
46,056 KB |
testcase_12 | AC | 135 ms
45,708 KB |
testcase_13 | AC | 140 ms
45,440 KB |
testcase_14 | AC | 132 ms
43,224 KB |
testcase_15 | AC | 137 ms
45,164 KB |
testcase_16 | AC | 138 ms
45,552 KB |
testcase_17 | AC | 129 ms
45,580 KB |
testcase_18 | AC | 141 ms
45,380 KB |
testcase_19 | AC | 140 ms
45,844 KB |
testcase_20 | AC | 150 ms
45,580 KB |
testcase_21 | AC | 147 ms
45,992 KB |
testcase_22 | AC | 146 ms
45,588 KB |
testcase_23 | AC | 148 ms
45,532 KB |
testcase_24 | AC | 143 ms
45,692 KB |
testcase_25 | AC | 144 ms
45,744 KB |
testcase_26 | AC | 145 ms
45,468 KB |
testcase_27 | AC | 144 ms
45,952 KB |
testcase_28 | AC | 128 ms
43,092 KB |
testcase_29 | AC | 129 ms
43,036 KB |
testcase_30 | AC | 122 ms
42,712 KB |
testcase_31 | AC | 125 ms
42,872 KB |
testcase_32 | AC | 128 ms
43,028 KB |
testcase_33 | AC | 53 ms
36,872 KB |
testcase_34 | AC | 52 ms
36,560 KB |
testcase_35 | AC | 52 ms
37,152 KB |
testcase_36 | AC | 53 ms
36,836 KB |
testcase_37 | AC | 52 ms
37,224 KB |
testcase_38 | AC | 57 ms
37,356 KB |
testcase_39 | AC | 115 ms
41,524 KB |
testcase_40 | AC | 113 ms
41,176 KB |
testcase_41 | AC | 133 ms
44,604 KB |
testcase_42 | AC | 117 ms
43,264 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); String[] base = new String[n]; int[][] counts = new int[n][26]; for (int i = 0; i < n; i++) { base[i] = sc.next(); for (int c : base[i].toCharArray()) { counts[i][c - 'a']++; } } Map<MyString, Integer> exists = new HashMap<>(); for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { counts[i][j]++; MyString x = new MyString(counts[i]); exists.put(x, exists.getOrDefault(x, 0) + 1); counts[i][j]--; } } for (MyString x : exists.keySet()) { if (exists.get(x) == 1) { System.out.println(x); return; } } System.out.println(-1); } static class MyString { String s; public MyString(int[] counts) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 26; i++) { for (int j = 0; j < counts[i]; j++) { sb.append((char)(i + 'a'));; } } s = sb.toString(); } public int hashCode() { return s.hashCode(); } public boolean equals(Object o) { MyString x = (MyString)o; return s.equals(x.s); } public String toString() { return s; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }