結果
問題 | No.697 池の数はいくつか |
ユーザー | バカらっく |
提出日時 | 2018-06-09 20:11:06 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 3,620 ms / 6,000 ms |
コード長 | 2,903 bytes |
コンパイル時間 | 1,799 ms |
コンパイル使用メモリ | 116,108 KB |
実行使用メモリ | 82,576 KB |
最終ジャッジ日時 | 2024-04-25 19:56:29 |
合計ジャッジ時間 | 26,531 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
25,124 KB |
testcase_01 | AC | 29 ms
25,140 KB |
testcase_02 | AC | 29 ms
25,232 KB |
testcase_03 | AC | 29 ms
25,228 KB |
testcase_04 | AC | 28 ms
24,972 KB |
testcase_05 | AC | 29 ms
25,228 KB |
testcase_06 | AC | 29 ms
25,228 KB |
testcase_07 | AC | 30 ms
27,140 KB |
testcase_08 | AC | 29 ms
25,356 KB |
testcase_09 | AC | 29 ms
25,264 KB |
testcase_10 | AC | 29 ms
25,260 KB |
testcase_11 | AC | 29 ms
22,968 KB |
testcase_12 | AC | 28 ms
25,140 KB |
testcase_13 | AC | 29 ms
25,228 KB |
testcase_14 | AC | 28 ms
23,344 KB |
testcase_15 | AC | 30 ms
25,396 KB |
testcase_16 | AC | 29 ms
25,228 KB |
testcase_17 | AC | 30 ms
27,288 KB |
testcase_18 | AC | 29 ms
25,392 KB |
testcase_19 | AC | 30 ms
27,520 KB |
testcase_20 | AC | 29 ms
27,292 KB |
testcase_21 | AC | 29 ms
25,388 KB |
testcase_22 | AC | 29 ms
25,104 KB |
testcase_23 | AC | 28 ms
23,088 KB |
testcase_24 | AC | 393 ms
47,884 KB |
testcase_25 | AC | 394 ms
47,596 KB |
testcase_26 | AC | 395 ms
50,024 KB |
testcase_27 | AC | 395 ms
47,480 KB |
testcase_28 | AC | 394 ms
49,780 KB |
testcase_29 | AC | 3,620 ms
82,092 KB |
testcase_30 | AC | 3,289 ms
77,828 KB |
testcase_31 | AC | 3,608 ms
82,576 KB |
testcase_32 | AC | 3,301 ms
75,732 KB |
testcase_33 | AC | 3,296 ms
77,948 KB |
testcase_34 | AC | 3,294 ms
75,796 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.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int rowCount = inpt[0]; int colCount = inpt[1]; bool[,] map = new bool[rowCount, colCount]; for (int i = 0; i < rowCount; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); for (int j = 0; j < colCount; j++) { if(inpt[j] == 1) { map[i, j] = true; } } } int[,] group = new int[rowCount, colCount]; int ans = 0; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { if(!map[i,j]) { continue; } if(group[i,j] != 0) { continue; } ans++; group[i, j] = ans; Queue<int[]> q = new Queue<int[]>(); q.Enqueue(new int[]{i,j}); while(q.Count > 0) { int[] pos = q.Dequeue(); for (int k = Math.Max(pos[0] - 1, 0); k <= Math.Min(pos[0] + 1, rowCount - 1); k++) { for (int l = Math.Max(pos[1] - 1, 0); l <= Math.Min(pos[1] + 1, colCount - 1); l++) { if(pos[0]==k&&pos[1]==l) { continue; } if(pos[0]!=k && pos[1]!=l) { continue; } if(!map[k,l]) { continue; } if(group[k,l] != 0) { continue; } group[k, l] = ans; q.Enqueue(new int[] { k, l }); } } } } } Console.WriteLine(ans); } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 4 3 1 1 1 0 1 0 1 0 1 1 1 1 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }