Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Scrooge_McDuck
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] size = new int[2];
- size = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int n = size[0];
- int m = size[1];
- int currow = 0;
- int curcol = 0;
- int[] linearr = new int[m];
- int[,] arr = new int[n, m];
- int counter = 0;
- int max = 0;
- int left = 0, right = 0, up = 0, down = 0;
- for (int row = 0; row < arr.GetLength(0); row++)
- {
- linearr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- for (int col = 0; col < arr.GetLength(1); col++)
- {
- arr[row, col] = linearr[col];
- if (arr[row, col] == 0)
- {
- currow = row;
- curcol = col;
- }
- }
- }
- while (true)
- {
- if (curcol != 0)
- left = arr[currow, curcol - 1];
- else
- left = 0;
- if (curcol != m - 1)
- right = arr[currow, curcol + 1];
- else
- right = 0;
- if (currow != 0)
- up = arr[currow - 1, curcol];
- else
- up = 0;
- if (currow != n - 1)
- down = arr[currow + 1, curcol];
- else
- down = 0;
- if (left == 0 && right == 0 && up == 0 && down == 0)
- break;
- if (left >= right && left >= up && left >= down)
- max = 1;
- else if (right >= up && right >= down)
- max = 2;
- else if (up >= down)
- max = 3;
- else
- max = 4;
- //max = 1
- //position =>left
- //max = 2
- //position =>right
- //max = 3
- //position =>up
- //max = 4
- //position =>down
- if (max == 1)
- {
- arr[currow, curcol - 1]--;
- curcol--;
- counter++;
- }
- else if (max == 2)
- {
- arr[currow, curcol + 1]--;
- curcol++;
- counter++;
- }
- else if (max == 3)
- {
- arr[currow - 1, curcol]--;
- currow--;
- counter++;
- }
- else if (max == 4)
- {
- arr[currow + 1, curcol]--;
- currow++;
- counter++;
- }
- }
- Console.WriteLine(counter);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement