Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Numerics;
- namespace Bounce
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] input = new int[2];
- input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- BigInteger[,] matrix = new BigInteger[input[0], input[1]];
- int n = input[0];
- int m = input[1];
- //declare matrix
- string direction = "downRight";
- int startingRow = 0;
- int startingCol = 0;
- BigInteger sum = 1;
- //fill matrix with correct vallues
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < m; col++)
- {
- matrix[row, col] = (int)Math.Pow(2, row + col);
- }
- }
- while (true)
- {
- if (direction == "downRight")
- {
- startingRow++;
- startingCol++;
- sum += matrix[startingRow, startingCol];
- if (startingRow == n-1 || startingCol == m-1)
- {
- if (startingRow == n-1)
- {
- direction = "rightUp";
- }
- else
- {
- direction = "downLeft";
- }
- }
- }
- if (direction == "rightUp")
- {
- startingRow--;
- startingCol++;
- sum += matrix[startingRow, startingCol];
- if (startingRow == 0 || startingCol == m-1)
- {
- if (startingCol == m-1)
- {
- direction = "upLeft";//To Do: direction = "upRight";
- }
- else
- {
- direction = "downRight"; //To Do: direction = "upLeft";
- }
- }
- }
- if (direction == "downLeft")
- {
- startingRow++;
- startingCol--;
- sum += matrix[startingRow, startingCol];
- if (startingRow == n - 1 || startingCol == 0)
- {
- if (startingCol == 0)
- {
- direction = "downRight";
- }
- else
- {
- direction = "upLeft";
- }
- }
- }
- if (direction == "upLeft")
- {
- startingRow--;
- startingCol--;
- sum += matrix[startingRow, startingCol];
- if (startingRow == 0 || startingCol == 0)
- {
- if (startingCol == 0)
- {
- direction = "upRight";
- }
- else
- {
- direction = "downLeft";
- }
- }
- }
- if (direction == "downLeft")
- {
- startingRow++;
- startingCol--;
- sum += matrix[startingRow, startingCol];
- if (startingRow == n-1 || startingCol == 0)
- {
- if (startingCol == 0)
- {
- direction = "downRight";
- }
- else
- {
- direction = "upLeft";
- }
- }
- }
- if (direction == "upRight")
- {
- startingRow--;
- startingCol++;
- sum += matrix[startingRow, startingCol];
- if (startingRow == 0 || startingCol == m-1)
- {
- if (startingRow == 0)
- {
- direction = "downRight";
- }
- else
- {
- direction = "upLeft";
- }
- }
- }
- if (direction == "upRight" || direction == "upLeft" || direction == "downLeft" || direction == "downRight" || direction == "rightUp" || direction == "downLeft")
- {
- if (startingRow == 0 && startingCol == 0 || startingRow == 0 && startingCol == m-1
- || startingRow == n-1 && startingCol == 0 || startingRow == n - 1 && startingCol == m - 1)
- {
- break;
- }
- }
- if (direction == "sss")
- {
- break;
- }
- }
- /*
- Console.WriteLine($"row-{startingRow} and col-{startingCol}");
- Console.WriteLine(direction);
- Print(matrix);
- */
- Console.WriteLine(sum);
- }
- static void Print(int[,] matrixToPrint)
- {
- for (int row = 0; row < matrixToPrint.GetLength(0); row++)
- {
- for (int col = 0; col < matrixToPrint.GetLength(1); col++)
- {
- Console.Write(matrixToPrint[row, col] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement