結果
問題 | No.1479 Matrix Eraser |
ユーザー | tenten |
提出日時 | 2021-04-28 09:49:55 |
言語 | Java21 (openjdk 21) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
50,512 KB |
testcase_01 | AC | 52 ms
50,428 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 375 ms
66,440 KB |
testcase_08 | AC | 555 ms
75,576 KB |
testcase_09 | AC | 1,026 ms
101,308 KB |
testcase_10 | AC | 1,611 ms
126,028 KB |
testcase_11 | AC | 1,211 ms
106,016 KB |
testcase_12 | AC | 483 ms
66,552 KB |
testcase_13 | AC | 570 ms
75,152 KB |
testcase_14 | AC | 468 ms
67,744 KB |
testcase_15 | AC | 199 ms
57,856 KB |
testcase_16 | AC | 503 ms
67,852 KB |
testcase_17 | AC | 1,901 ms
140,476 KB |
testcase_18 | AC | 1,968 ms
140,212 KB |
testcase_19 | AC | 1,969 ms
140,684 KB |
testcase_20 | AC | 1,907 ms
140,656 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 2,005 ms
141,128 KB |
testcase_24 | AC | 1,864 ms
140,388 KB |
testcase_25 | WA | - |
testcase_26 | AC | 2,025 ms
140,620 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 199 ms
57,100 KB |
testcase_38 | AC | 880 ms
109,520 KB |
testcase_39 | AC | 1,465 ms
145,520 KB |
testcase_40 | AC | 53 ms
50,464 KB |
ソースコード
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(); } }