結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2018-06-10 12:47:00 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 4,340 ms / 6,000 ms |
コード長 | 2,098 bytes |
コンパイル時間 | 1,089 ms |
コンパイル使用メモリ | 105,856 KB |
実行使用メモリ | 77,304 KB |
最終ジャッジ日時 | 2024-11-08 07:43:40 |
合計ジャッジ時間 | 29,006 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
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; using System.Text; using System.Threading.Tasks; namespace _697 { class Program { static void Main(string[] args) { var tokens = Console.ReadLine().Split().Select(int.Parse).ToList(); var h = tokens[0]; var w = tokens[1]; var field = new List<List<int>>(); for (int i = 0; i < h; i++) { var row = Console.ReadLine().Split().Select(int.Parse).ToList(); field.Add(row); } int counter = 0; for (int x = 0; x < h; x++) { for (int y = 0; y < w; y++) { if (field[x][y] == 0) { continue; } counter++; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(Tuple.Create(x, y)); while (queue.Any()) { var coordinate = queue.Dequeue(); var x1 = coordinate.Item1; var y1 = coordinate.Item2; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (Math.Abs(dx + dy) != 1) { continue; } var x2 = x1 + dx; var y2 = y1 + dy; if (0 <= x2 && x2 < h && 0 <= y2 && y2 < w && field[x2][y2] == 1) { field[x2][y2] = 0; queue.Enqueue(Tuple.Create(x2, y2)); } } } } } } Console.WriteLine(counter); } } }