結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2018-06-09 17:54:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 4,835 bytes |
コンパイル時間 | 4,403 ms |
コンパイル使用メモリ | 111,672 KB |
実行使用メモリ | 825,784 KB |
最終ジャッジ日時 | 2024-11-25 12:40:46 |
合計ジャッジ時間 | 60,977 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 TLE * 5 MLE * 3 |
コンパイルメッセージ
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 ichimatu { class Program { static char[,] map = new char[3000, 3000]; static int gyouMax; static int retuMax; static void Main(string[] args) { var input = Console.ReadLine(); var d = input.Split(' '); gyouMax = Int32.Parse(d[0]); retuMax = Int32.Parse(d[1]); var input2list = new List<string>(); for (int i = 0; i < gyouMax; i++) { input2list.Add(Console.ReadLine()); } for (int i = 0; i < gyouMax; i++) { var dd = input2list[i].Split(' '); for (int j = 0; j < retuMax; j++) { map[i, j] = char.Parse(dd[j]); } } var total = 0; for (int i = 0; i < gyouMax; i++) { for (int j = 0; j < retuMax; j++) { // 「1」を見つける if (map[i, j] == '1') { // 周辺探索 exec周辺探索2(i, j); total += 1; } } } Console.WriteLine(total); } private static void exec周辺探索2(int gyou, int retu) { var tansaku_gyouList = new Queue<int>(); var tansaku_retuList = new Queue<int>(); // 見つけた場所をキューに入れる tansaku_gyouList.Enqueue(gyou); tansaku_retuList.Enqueue(retu); // キューをマーク&探索 while (tansaku_gyouList.Count !=0) { var targetGyou = tansaku_gyouList.Dequeue(); var targetRetu = tansaku_retuList.Dequeue(); // マークする map[targetGyou, targetRetu] = '9'; // 右をチェックする if (targetRetu + 1 < retuMax) { if (map[targetGyou, targetRetu + 1] == '1') { tansaku_gyouList.Enqueue(targetGyou); tansaku_retuList.Enqueue(targetRetu + 1); } } // 上をチェックする if (0 <= targetGyou - 1) { if (map[targetGyou - 1, targetRetu] == '1') { tansaku_gyouList.Enqueue(targetGyou-1); tansaku_retuList.Enqueue(targetRetu ); } } // 下をチェックする if (targetGyou + 1 < gyouMax) { if (map[targetGyou + 1, targetRetu] == '1') { tansaku_gyouList.Enqueue(targetGyou + 1); tansaku_retuList.Enqueue(targetRetu); } } // 左をチェックする if (0 <= targetRetu - 1) { if (map[targetGyou, targetRetu - 1] == '1') { tansaku_gyouList.Enqueue(targetGyou ); tansaku_retuList.Enqueue(targetRetu-1); } } } } private static void exec周辺探索(int gyou, int retu) { var tansaku_gyouList = new List<int>(); var tansaku_retuList = new List<int>(); // 見つけた場所を探索済みにする map[gyou, retu] = '9'; // 探索対象をキューに入れる // 右をチェックする if (retu + 1 < retuMax) { if (map[gyou, retu + 1] == '1') { exec周辺探索(gyou, retu + 1); } } // 上をチェックする if (0 <= gyou - 1) { if (map[gyou - 1, retu] == '1') { exec周辺探索(gyou - 1, retu); } } // 下をチェックする if (gyou + 1 < gyouMax) { if (map[gyou + 1, retu] == '1') { exec周辺探索(gyou + 1, retu); } } // 左をチェックする if (0 <= retu - 1) { if (map[gyou, retu - 1] == '1') { exec周辺探索(gyou, retu - 1); } } } } }