結果
問題 | No.1479 Matrix Eraser |
ユーザー | さかぽん |
提出日時 | 2021-07-01 19:20:39 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,344 ms / 3,000 ms |
コード長 | 2,341 bytes |
コンパイル時間 | 1,417 ms |
コンパイル使用メモリ | 115,208 KB |
実行使用メモリ | 174,580 KB |
最終ジャッジ日時 | 2024-06-28 08:58:18 |
合計ジャッジ時間 | 24,744 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
24,292 KB |
testcase_01 | AC | 34 ms
24,332 KB |
testcase_02 | AC | 33 ms
23,984 KB |
testcase_03 | AC | 34 ms
29,824 KB |
testcase_04 | AC | 34 ms
24,084 KB |
testcase_05 | AC | 34 ms
24,084 KB |
testcase_06 | AC | 34 ms
26,260 KB |
testcase_07 | AC | 145 ms
56,440 KB |
testcase_08 | AC | 233 ms
68,052 KB |
testcase_09 | AC | 532 ms
98,440 KB |
testcase_10 | AC | 982 ms
137,700 KB |
testcase_11 | AC | 590 ms
109,156 KB |
testcase_12 | AC | 178 ms
62,840 KB |
testcase_13 | AC | 237 ms
68,372 KB |
testcase_14 | AC | 180 ms
63,796 KB |
testcase_15 | AC | 68 ms
45,960 KB |
testcase_16 | AC | 192 ms
65,972 KB |
testcase_17 | AC | 1,326 ms
153,748 KB |
testcase_18 | AC | 1,324 ms
152,300 KB |
testcase_19 | AC | 1,338 ms
155,992 KB |
testcase_20 | AC | 1,344 ms
154,028 KB |
testcase_21 | AC | 1,331 ms
156,076 KB |
testcase_22 | AC | 1,328 ms
153,876 KB |
testcase_23 | AC | 1,317 ms
158,548 KB |
testcase_24 | AC | 1,309 ms
158,476 KB |
testcase_25 | AC | 1,322 ms
154,252 KB |
testcase_26 | AC | 1,318 ms
154,316 KB |
testcase_27 | AC | 321 ms
55,944 KB |
testcase_28 | AC | 319 ms
56,076 KB |
testcase_29 | AC | 321 ms
53,644 KB |
testcase_30 | AC | 318 ms
52,504 KB |
testcase_31 | AC | 317 ms
54,164 KB |
testcase_32 | AC | 249 ms
50,696 KB |
testcase_33 | AC | 250 ms
50,560 KB |
testcase_34 | AC | 249 ms
52,236 KB |
testcase_35 | AC | 248 ms
50,836 KB |
testcase_36 | AC | 246 ms
50,180 KB |
testcase_37 | AC | 83 ms
28,816 KB |
testcase_38 | AC | 519 ms
83,044 KB |
testcase_39 | AC | 804 ms
174,580 KB |
testcase_40 | AC | 31 ms
21,940 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; class D { static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); static (int, int) Read2() { var a = Read(); return (a[0], a[1]); } static void Main() { var (h, w) = Read2(); var a = Array.ConvertAll(new bool[h], _ => Read()); var amax = 500000; var d = new List<int[]>[amax + 1]; var dr = new Dictionary<int, int>[amax + 1]; var dc = new Dictionary<int, int>[amax + 1]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { var k = a[i][j]; if (k == 0) continue; if (d[k] == null) { d[k] = new List<int[]>(); dr[k] = new Dictionary<int, int>(); dc[k] = new Dictionary<int, int>(); } if (!dr[k].ContainsKey(i)) dr[k][i] = dr[k].Count; if (!dc[k].ContainsKey(j)) dc[k][j] = dc[k].Count; d[k].Add(new[] { dr[k][i], dc[k][j] }); } } var r = 0L; for (int k = 0; k <= amax; k++) { if (d[k] == null) continue; if (d[k].Count == 1) { r++; continue; } var bm = new BipartiteMatching(dr[k].Count, dc[k].Count); bm.AddEdges(d[k].ToArray()); var res = bm.Dinic(); r += res.Length; } Console.WriteLine(r); } } public class BipartiteMatching { int n1; List<int>[] map; public int[][] Map; int[] match; bool[] u; // 0 <= v1 < n1, 0 <= v2 < n2 public BipartiteMatching(int n1, int n2) { this.n1 = n1; var n = n1 + n2; map = Array.ConvertAll(new bool[n], _ => new List<int>()); u = new bool[n]; } public void AddEdge(int from, int to) { map[from].Add(n1 + to); map[n1 + to].Add(from); } // { from, to } public void AddEdges(int[][] des) { foreach (var e in des) AddEdge(e[0], e[1]); } bool Dfs(int v1) { u[v1] = true; foreach (var v2 in Map[v1]) { var u1 = match[v2]; if (u1 == -1 || !u[u1] && Dfs(u1)) { match[v1] = v2; match[v2] = v1; return true; } } return false; } public int[][] Dinic() { Map = Array.ConvertAll(map, l => l.ToArray()); match = Array.ConvertAll(map, _ => -1); for (int v1 = 0; v1 < n1; ++v1) { if (match[v1] != -1) continue; Array.Clear(u, 0, u.Length); Dfs(v1); } var r = new List<int[]>(); for (int v1 = 0; v1 < n1; ++v1) if (match[v1] != -1) r.Add(new[] { v1, match[v1] - n1 }); return r.ToArray(); } }