Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _4._ScroogeMcDuck
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int[,] matrix = new int[input[0], input[1]];
- int row = input[0];
- int col = input[1];
- int rowStart = 0;
- int colStart = 0;
- int coins = 0;
- for (row = 0; row < matrix.GetLength(0); row++)
- {
- var inputAsArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- for (col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = inputAsArray[col];
- if (matrix[row, col] == 0)
- {
- rowStart = row;
- colStart = col;
- }
- }
- }
- int currentLeft = 0;
- int currentRight = 0;
- int currentUp = 0;
- int currentDown = 0;
- while (true)
- {
- if (colStart - 1 == -1)
- {
- currentLeft = 0;
- }
- else
- {
- currentLeft = matrix[rowStart, colStart - 1];
- }
- if (colStart + 1 == input[1])
- {
- currentRight = 0;
- }
- else
- {
- currentRight = matrix[rowStart, colStart + 1];
- }
- if (rowStart - 1 == -1)
- {
- currentUp = 0;
- }
- else
- {
- currentUp = matrix[rowStart - 1, colStart];
- }
- if (rowStart + 1 == input[0])
- {
- currentDown = 0;
- }
- else
- {
- currentDown = matrix[rowStart + 1, colStart];
- }
- if (currentLeft == 0 && currentRight == 0 && currentUp == 0 && currentDown == 0)
- {
- Console.WriteLine(coins);
- break;
- }
- if (currentLeft >= currentRight && currentLeft >= currentDown && currentLeft >= currentUp)
- {
- matrix[rowStart, --colStart] -= 1;
- coins++;
- }
- else if (currentRight >= currentDown && currentRight >= currentUp)
- {
- matrix[rowStart, ++colStart] -= 1;
- coins++;
- }
- else if (currentUp >= currentDown)
- {
- matrix[--rowStart, colStart] -= 1;
- coins++;
- }
- else
- {
- matrix[++rowStart, colStart] -= 1;
- coins++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment