結果
| 問題 |
No.1994 Confusing Name
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-07-11 14:29:53 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,883 bytes |
| コンパイル時間 | 3,109 ms |
| コンパイル使用メモリ | 80,344 KB |
| 実行使用メモリ | 74,428 KB |
| 最終ジャッジ日時 | 2024-06-13 02:45:00 |
| 合計ジャッジ時間 | 8,721 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 TLE * 1 -- * 18 |
ソースコード
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();
ArrayList<ArrayList<Name>> names = new ArrayList<>();
for (int i = 0; i <= 10; i++) {
names.add(new ArrayList<>());
}
for (int i = 0; i < n; i++) {
Name x = new Name(i, sc.next().toCharArray());
names.get(x.length()).add(x);
}
int[] ans = new int[n];
for (int i = 1; i <= 10; i++) {
ArrayList<Name> tmp = names.get(i);
for (int j = 0; j < i; j++) {
HashMap<Name, ArrayList<Integer>> group = new HashMap<>();
Name.mask = j;
for (Name x : tmp) {
if (!group.containsKey(x)) {
group.put(x, new ArrayList<>());
}
group.get(x).add(x.idx);
}
for (ArrayList<Integer> x : group.values()) {
if (x.size() <= 1) {
continue;
}
for (int y : x) {
ans[y] += x.size() - 1;
}
}
}
}
StringBuilder sb = new StringBuilder();
for (int x : ans) {
sb.append(x).append("\n");
}
System.out.print(sb);
}
static class Name {
static int mask;
int idx;
char[] arr;
public Name(int idx, char[] arr) {
this.idx = idx;
this.arr = arr;
}
public int length() {
return arr.length;
}
public int hashCode() {
return length();
}
public boolean equals(Object o) {
Name n = (Name)o;
for (int i = 0; i < arr.length; i++) {
if (mask == i) {
continue;
}
if (arr[i] != n.arr[i]) {
return false;
}
}
return true;
}
}
}
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();
}
}
tenten