Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace DictionaryLKSH
- {
- class MainClass
- {
- static void fun(int[][] field, int Cx, int Cy, ref bool[,] checker, ref int answer)
- {
- answer++;
- checker[Cx, Cy] = false;
- if (checker[Cx, Cy] == false && checker[Cx + 1, Cy] == false && checker[Cx - 1, Cy] == false && checker[Cx, Cy + 1] == false && checker[Cx, Cy - 1] == false)
- return;
- else
- {
- if (checker[Cx + 1, Cy])
- {
- checker[Cx + 1, Cy] = false;
- fun(field, Cx + 1, Cy, ref checker, ref answer);
- }
- if (checker[Cx - 1, Cy])
- {
- checker[Cx - 1, Cy] = false;
- fun(field, Cx - 1, Cy, ref checker, ref answer);
- }
- if (checker[Cx, Cy + 1])
- {
- checker[Cx, Cy + 1] = false;
- fun(field, Cx, Cy + 1, ref checker, ref answer);
- }
- if (checker[Cx, Cy - 1])
- {
- checker[Cx, Cy - 1] = false;
- fun(field, Cx, Cy - 1, ref checker, ref answer);
- }
- }
- }
- public static void Main(string[] args)
- {
- int[] TempArray = Console.ReadLine().Split(' ').Select(e => Convert.ToInt32(e)).ToArray();
- int n = TempArray[0] + 2, m = TempArray[1] + 2;
- int[][] Field = new int[n][];
- int answer = 0;
- int realAnswer = 0;
- for (int i = 0; i < n; i++)
- Field[i] = new int[m];
- bool[,] checker = new bool[n, m];
- for (int i = 0; i < n; i++)//wall of 2
- for (int j = 0; j < m; j++)
- {
- if (i == 0 || i == n - 1 || j == 0 || j == m - 1) Field[i][j] = 2;
- else Field[i][j] = 0;
- }
- for (int i = 1; i < n - 1; i++)//fill the mass
- {
- TempArray = Console.ReadLine().Split(' ').Select(e => Convert.ToInt32(e)).ToArray();
- for (int j = 1; j < m - 1; j++)
- {
- Field[i][j] = TempArray[j - 1];
- }
- }
- for (int i = 0; i < n; i++)//hcecker
- for (int j = 0; j < m; j++)
- if (Field[i][j] == 1) checker[i, j] = true;//shoulde be checked
- else checker[i, j] = false;//checked
- for (int i = 1; i < n - 1; i++)//search
- {
- for (int j = 1; j < m; j++)
- {
- if (checker[i, j])
- {
- fun(Field, i, j, ref checker, ref answer);
- if (answer > realAnswer)
- {
- realAnswer = answer;
- }
- answer = 0;
- }
- }
- }
- Console.WriteLine(realAnswer);
- }
- }
- }
- /*
- 6 10
- 1 1 0 0 0 0 0 1 1 0
- 0 1 1 1 0 1 0 1 1 0
- 0 1 1 0 1 0 1 0 1 0
- 0 1 0 1 0 1 0 1 1 0
- 0 1 1 1 0 0 1 1 1 0
- 0 0 0 0 0 0 0 0 0 0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement