結果

問題 No.1994 Confusing Name
ユーザー tentententen
提出日時 2023-02-25 12:42:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 897 ms / 2,000 ms
コード長 2,390 bytes
コンパイル時間 3,596 ms
コンパイル使用メモリ 90,776 KB
実行使用メモリ 105,228 KB
最終ジャッジ日時 2023-10-11 12:07:56
合計ジャッジ時間 19,707 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,604 KB
testcase_01 AC 43 ms
49,644 KB
testcase_02 AC 43 ms
49,468 KB
testcase_03 AC 43 ms
49,408 KB
testcase_04 AC 42 ms
49,668 KB
testcase_05 AC 78 ms
51,948 KB
testcase_06 AC 103 ms
52,404 KB
testcase_07 AC 55 ms
50,296 KB
testcase_08 AC 89 ms
51,424 KB
testcase_09 AC 91 ms
52,260 KB
testcase_10 AC 84 ms
52,204 KB
testcase_11 AC 78 ms
51,416 KB
testcase_12 AC 767 ms
87,268 KB
testcase_13 AC 893 ms
105,228 KB
testcase_14 AC 851 ms
96,020 KB
testcase_15 AC 783 ms
90,108 KB
testcase_16 AC 704 ms
89,472 KB
testcase_17 AC 779 ms
90,220 KB
testcase_18 AC 847 ms
96,164 KB
testcase_19 AC 897 ms
98,104 KB
testcase_20 AC 894 ms
97,968 KB
testcase_21 AC 261 ms
60,620 KB
testcase_22 AC 194 ms
57,644 KB
testcase_23 AC 832 ms
91,500 KB
testcase_24 AC 836 ms
89,640 KB
testcase_25 AC 545 ms
81,816 KB
testcase_26 AC 306 ms
62,920 KB
testcase_27 AC 760 ms
86,548 KB
testcase_28 AC 573 ms
81,196 KB
testcase_29 AC 186 ms
57,836 KB
testcase_30 AC 605 ms
81,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        int n = sc.nextInt();
        ArrayList<ArrayList<String>> all = new ArrayList<>();
        HashMap<String, Integer> counts = new HashMap<>();
        for (int i = 0; i < n; i++) {
            char[] inputs = sc.next().toCharArray();
            char save;
            ArrayList<String> tmp = new ArrayList<>();
            for (int j = 0; j < inputs.length; j++) {
                save = inputs[j];
                inputs[j] = '?';
                String current = new String(inputs);
                tmp.add(current);
                counts.put(current, counts.getOrDefault(current, 0) + 1);
                inputs[j] = save;
            }
            all.add(tmp);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int ans = 0;
            for (String x : all.get(i)) {
                ans += counts.get(x) - 1;
            }
            sb.append(ans).append("\n");
        }
        System.out.print(sb);
    }
}
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();
    }
    
}
0