結果
| 問題 | No.1479 Matrix Eraser |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-04-28 09:49:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,380 bytes |
| 記録 | |
| コンパイル時間 | 2,385 ms |
| コンパイル使用メモリ | 89,772 KB |
| 実行使用メモリ | 146,484 KB |
| 最終ジャッジ日時 | 2024-07-07 04:39:38 |
| 合計ジャッジ時間 | 39,448 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 WA * 18 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int h = sc.nextInt();
int w = sc.nextInt();
ArrayList<HashMap<Integer, Integer>> rows = new ArrayList<>();
ArrayList<HashMap<Integer, Integer>> cols = new ArrayList<>();
for (int i = 0; i < w; i++) {
cols.add(new HashMap<>());
}
for (int i = 0; i < h; i++) {
rows.add(new HashMap<>());
for (int j = 0; j < w; j++) {
int x = sc.nextInt();
if (x == 0) {
continue;
}
rows.get(i).put(x, rows.get(i).getOrDefault(x, 0) + 1);
cols.get(j).put(x, cols.get(j).getOrDefault(x, 0) + 1);
}
}
TreeMap<Integer, PriorityQueue<Unit>> all = new TreeMap<>();
for (int i = 0; i < h; i++) {
for (Map.Entry<Integer, Integer> entry : rows.get(i).entrySet()) {
int key = entry.getKey();
int value = entry.getValue();
if (!all.containsKey(-key)) {
all.put(-key, new PriorityQueue<>());
}
all.get(-key).add(new Unit(value, true));
}
}
for (int i = 0; i < w; i++) {
for (Map.Entry<Integer, Integer> entry : cols.get(i).entrySet()) {
int key = entry.getKey();
int value = entry.getValue();
if (!all.containsKey(-key)) {
all.put(-key, new PriorityQueue<>());
}
all.get(-key).add(new Unit(value, false));
}
}
int ans = 0;
for (PriorityQueue<Unit> queue : all.values()) {
int rowCount = 0;
int colCount = 0;
while (queue.size() > 0) {
Unit u = queue.poll();
if (u.isRow) {
if (u.value > colCount) {
ans++;
rowCount++;
}
} else {
if (u.value > rowCount) {
ans++;
colCount++;
}
}
}
}
System.out.println(ans);
}
static class Unit implements Comparable<Unit> {
int value;
boolean isRow;
public Unit(int value, boolean isRow) {
this.isRow = isRow;
this.value = value;
}
public int compareTo(Unit another) {
return another.value - value;
}
public String toString() {
return value + ":" + isRow;
}
}
}
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 String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten