結果

問題 No.1994 Confusing Name
ユーザー tentententen
提出日時 2022-07-11 14:36:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,307 ms / 2,000 ms
コード長 2,158 bytes
コンパイル時間 2,815 ms
コンパイル使用メモリ 74,960 KB
実行使用メモリ 160,380 KB
最終ジャッジ日時 2023-09-03 22:23:20
合計ジャッジ時間 23,304 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,692 KB
testcase_01 AC 45 ms
49,252 KB
testcase_02 AC 46 ms
49,236 KB
testcase_03 AC 45 ms
49,332 KB
testcase_04 AC 46 ms
49,204 KB
testcase_05 AC 76 ms
51,872 KB
testcase_06 AC 109 ms
52,788 KB
testcase_07 AC 58 ms
50,312 KB
testcase_08 AC 92 ms
51,840 KB
testcase_09 AC 112 ms
52,516 KB
testcase_10 AC 91 ms
51,548 KB
testcase_11 AC 77 ms
51,396 KB
testcase_12 AC 1,139 ms
112,484 KB
testcase_13 AC 1,209 ms
153,980 KB
testcase_14 AC 1,189 ms
157,240 KB
testcase_15 AC 1,127 ms
123,640 KB
testcase_16 AC 1,076 ms
118,388 KB
testcase_17 AC 1,035 ms
120,452 KB
testcase_18 AC 1,166 ms
156,144 KB
testcase_19 AC 1,307 ms
159,176 KB
testcase_20 AC 1,258 ms
160,380 KB
testcase_21 AC 377 ms
73,028 KB
testcase_22 AC 206 ms
59,900 KB
testcase_23 AC 1,042 ms
123,828 KB
testcase_24 AC 1,170 ms
121,748 KB
testcase_25 AC 690 ms
105,180 KB
testcase_26 AC 400 ms
72,904 KB
testcase_27 AC 1,046 ms
114,516 KB
testcase_28 AC 719 ms
100,228 KB
testcase_29 AC 202 ms
60,360 KB
testcase_30 AC 987 ms
113,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0