結果
問題 | No.1994 Confusing Name |
ユーザー |
![]() |
提出日時 | 2022-07-11 14:36:21 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,385 ms / 2,000 ms |
コード長 | 2,158 bytes |
コンパイル時間 | 2,487 ms |
コンパイル使用メモリ | 79,296 KB |
実行使用メモリ | 143,324 KB |
最終ジャッジ日時 | 2024-06-13 03:01:37 |
合計ジャッジ時間 | 23,510 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
import java.io.*;import java.util.*;public class Main {public static void main(String[] args) throws Exception {Scanner sc = new Scanner();int n = sc.nextInt();HashMap<Name, ArrayList<Integer>> group = new HashMap<>();for (int i = 0; i < n; i++) {char[] values = sc.next().toCharArray();for (int j = 0; j < values.length; j++) {char c = values[j];values[j] = '.';Name x = new Name(i, new String(values));if (!group.containsKey(x)) {group.put(x, new ArrayList<>());}group.get(x).add(x.idx);values[j] = c;}}int[] ans = new int[n];for (ArrayList<Integer> list : group.values()) {for (int x : list) {ans[x] += list.size() - 1;}}StringBuilder sb = new StringBuilder();for (int x : ans) {sb.append(x).append("\n");}System.out.print(sb);}static class Name {int idx;String s;public Name(int idx, String s) {this.idx = idx;this.s = s;}public int hashCode() {return s.hashCode();}public boolean equals(Object o) {Name n = (Name)o;return s.equals(n.s);}}}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 next() throws Exception {if (!st.hasMoreTokens()) {st = new StringTokenizer(br.readLine());}return st.nextToken();}}