Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Bounce
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int rows = input[0];
- int cols = input[1];
- ulong[,] board = new ulong[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- board[row, col] = (ulong)Math.Pow(2, row + col);
- }
- }
- int startRow = 1;
- int startCol = 1;
- int directionRow = 1;
- int directionCol = 1;
- ulong sum = 1;
- if (rows == 1 || cols ==1)
- {
- Console.WriteLine(sum);
- return;
- }
- while (!HitCorner(rows, cols ,startRow, startCol))
- {
- sum += board[startRow, startCol];
- if (directionRow == 1)
- {
- startRow++;
- }
- else
- {
- startRow --;
- }
- if (directionCol == 1)
- {
- startCol++;
- }
- else
- {
- startCol--;
- }
- if(startRow >= rows)
- {
- directionRow = 0;
- startRow -= 2;
- }
- else if(startRow < 0)
- {
- directionRow = 1;
- startRow+=2;
- }
- if (startCol >= cols)
- {
- directionCol = 0;
- startCol -= 2;
- }
- else if(startCol < 0)
- {
- directionCol = 1;
- startCol+=2;
- }
- if (rows == 1)
- {
- startRow = 0;
- }
- }
- sum += board[startRow, startCol];
- Console.WriteLine(sum);
- }
- private static bool HitCorner(int rows, int cols, int startRow, int startCol)
- {
- return startRow == rows - 1 && startCol == 0
- || startCol == cols - 1 && startRow == 0 ||
- startCol == cols - 1 && startRow == rows - 1 ||
- startRow == 0 && startCol == 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement