結果
| 問題 |
No.1479 Matrix Eraser
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-17 13:23:10 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,165 bytes |
| コンパイル時間 | 1,030 ms |
| コンパイル使用メモリ | 113,216 KB |
| 実行使用メモリ | 71,996 KB |
| 最終ジャッジ日時 | 2024-07-03 20:28:21 |
| 合計ジャッジ時間 | 21,897 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 23 WA * 13 TLE * 1 -- * 2 |
コンパイルメッセージ
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;
using System.Linq;
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 d = new Dictionary<int, List<(int, int)>>();
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.ContainsKey(k)) d[k] = new List<(int, int)>();
d[k].Add((i, j));
}
}
Console.WriteLine(d.Values.Sum(ForGroup));
}
static int ForGroup(List<(int, int)> ps)
{
var r = 0;
var d = new Dictionary<int, HashSet<int>>();
foreach (var (i, j) in ps)
{
var j2 = 500 + j;
if (!d.ContainsKey(i)) d[i] = new HashSet<int>();
d[i].Add(j2);
if (!d.ContainsKey(j2)) d[j2] = new HashSet<int>();
d[j2].Add(i);
}
while (d.Count > 0)
{
var (i, l) = d.OrderBy(p => -p.Value.Count).First();
d.Remove(i);
foreach (var j in l)
{
d[j].Remove(i);
if (d[j].Count == 0) d.Remove(j);
}
r++;
}
return r;
}
}