結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
バカらっく
|
| 提出日時 | 2018-06-09 20:07:04 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,871 bytes |
| 記録 | |
| コンパイル時間 | 1,076 ms |
| コンパイル使用メモリ | 118,232 KB |
| 実行使用メモリ | 79,740 KB |
| 最終ジャッジ日時 | 2024-11-25 12:59:38 |
| 合計ジャッジ時間 | 22,636 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 6 WA * 26 |
コンパイルメッセージ
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(i - 1, 0); k <= Math.Min(i + 1, rowCount - 1); k++) {
for (int l = Math.Max(j - 1, 0); l <= Math.Min(j + 1, colCount - 1); l++) {
if(i==k&&j==l) {
continue;
}
if(i!=k && j!=l) {
continue;
}
if(!map[k,l]) {
continue;
}
if(group[k,l] != 0) {
continue;
}
group[k, l] = group[i, j];
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 0 1
0 1 0
1 0 1
0 1 0
";
}
public static void Main(string[] args)
{
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
バカらっく