Advertisement
MeliDragon

Untitled

Mar 9th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Bounce
  7. {
  8. internal class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13. int rows = input[0];
  14. int cols = input[1];
  15. ulong[,] board = new ulong[rows, cols];
  16.  
  17. for (int row = 0; row < rows; row++)
  18. {
  19. for (int col = 0; col < cols; col++)
  20. {
  21.  
  22. board[row, col] = (ulong)Math.Pow(2, row + col);
  23.  
  24. }
  25. }
  26. int startRow = 1;
  27. int startCol = 1;
  28. int directionRow = 1;
  29. int directionCol = 1;
  30. ulong sum = 1;
  31.  
  32. if (rows == 1 || cols ==1)
  33. {
  34. Console.WriteLine(sum);
  35. return;
  36. }
  37.  
  38.  
  39. while (!HitCorner(rows, cols ,startRow, startCol))
  40. {
  41. sum += board[startRow, startCol];
  42.  
  43. if (directionRow == 1)
  44. {
  45. startRow++;
  46. }
  47. else
  48. {
  49. startRow --;
  50. }
  51.  
  52. if (directionCol == 1)
  53. {
  54. startCol++;
  55. }
  56. else
  57. {
  58. startCol--;
  59. }
  60.  
  61. if(startRow >= rows)
  62. {
  63. directionRow = 0;
  64. startRow -= 2;
  65. }
  66. else if(startRow < 0)
  67. {
  68. directionRow = 1;
  69. startRow+=2;
  70. }
  71.  
  72. if (startCol >= cols)
  73. {
  74. directionCol = 0;
  75. startCol -= 2;
  76. }
  77. else if(startCol < 0)
  78. {
  79. directionCol = 1;
  80. startCol+=2;
  81. }
  82. if (rows == 1)
  83. {
  84. startRow = 0;
  85. }
  86. }
  87. sum += board[startRow, startCol];
  88. Console.WriteLine(sum);
  89. }
  90.  
  91.  
  92.  
  93. private static bool HitCorner(int rows, int cols, int startRow, int startCol)
  94. {
  95. return startRow == rows - 1 && startCol == 0
  96. || startCol == cols - 1 && startRow == 0 ||
  97. startCol == cols - 1 && startRow == rows - 1 ||
  98. startRow == 0 && startCol == 0;
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement