Statistics

Problem Statement for "MountainMap"

Problem Statement

A mountain map is a NxM rectangular grid where each cell has a height. The heights are positive integers between 1 and N*M, inclusive, and no two distinct cells have equal heights. Two cells are called neighboring if they share a side or a corner. A cell is called locally minimal if its height is less than the heights of all its neighboring cells.

You are given a String[] data. The j-th character of the i-th element of data is 'X' if the j-th cell in the i-th row of the mountain map is locally minimal, and '.' otherwise. Calculate the number of distinct mountain maps that match the data. Return the result modulo 12345678.

Definition

Class:
MountainMap
Method:
count
Parameters:
String[]
Returns:
int
Method signature:
int count(String[] data)
(be sure your method is public)

Constraints

  • data will contain between 1 and 4 elements, inclusive.
  • Each element of data will contain between 1 and 7 characters, inclusive.
  • All elements of data will contain the same number of characters.
  • Each character in each element of data will be '.' or uppercase 'X'.

Examples

  1. {".X."}

    Returns: 2

    The middle cell is lower than its neighbors, so its height is 1. There are two variants of heights for the other cells: the left cell's height is 2 and the right cell's height is 3, or vice versa.

  2. {"X.", ".X"}

    Returns: 0

    No two neighboring cells can both be locally minimal, so the answer is 0.

  3. {"...", "..."}

    Returns: 0

    Each mountain map contains at least one locally minimal cell.

  4. {"X.", "..", ".X"}

    Returns: 60

  5. {"X.X", "...", "X.X"}

    Returns: 4800

  6. {"..X.."}

    Returns: 6

  7. {"X"}

    Returns: 1

  8. {".......", ".......", ".......", "......."}

    Returns: 0

  9. {".X.X", "...X"}

    Returns: 0

  10. {"X.", ".X", "..", ".."}

    Returns: 0

  11. {"XX"}

    Returns: 0

  12. {".......", ".X.X..X", "....X.."}

    Returns: 0

  13. {"..X.X.X", "....X..", "X..X.X."}

    Returns: 0

  14. {"X", "X", "."}

    Returns: 0

  15. {"X", "X", "X"}

    Returns: 0

  16. {"XXX...."}

    Returns: 0

  17. {"X..", "X..", "..."}

    Returns: 0

  18. {"XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX"}

    Returns: 0

  19. {".X"}

    Returns: 1

  20. {"..X"}

    Returns: 1

  21. {"X..."}

    Returns: 1

  22. {"X..X."}

    Returns: 20

  23. {"X....."}

    Returns: 1

  24. {"...X..."}

    Returns: 20

  25. {"X", "."}

    Returns: 1

  26. {"..", ".X"}

    Returns: 6

  27. {"...", "X.X"}

    Returns: 60

  28. {"....", "X..."}

    Returns: 840

  29. {"....X", "..X.."}

    Returns: 68040

  30. {"X.....", "..X..X"}

    Returns: 6237000

  31. {"X......", "..X...X"}

    Returns: 3816648

  32. {".", ".", "X"}

    Returns: 1

  33. {"..", ".X", ".."}

    Returns: 120

  34. {"...", ".X.", "..."}

    Returns: 40320

  35. {"X.X.", "....", "..X."}

    Returns: 3463320

  36. {"..X..", "X....", "..X.X"}

    Returns: 8606478

  37. {"....X.", "......", ".X...X"}

    Returns: 869490

  38. {"X.X.X.X", ".......", ".X.X.X."}

    Returns: 11190438

  39. {".", "X", ".", "X"}

    Returns: 5

  40. {"X.", "..", ".X", ".."}

    Returns: 2100

  41. {"X..", "...", "..X", "..."}

    Returns: 5809020

  42. {"....", "...X", "....", ".X.X"}

    Returns: 4688748

  43. {"X....", "..X.X", ".....", "X.X.X"}

    Returns: 3559302

  44. {".....X", "..X...", "X.....", "..X.X."}

    Returns: 4637916

  45. {"X......", ".......", ".......", "......."}

    Returns: 1221642

  46. {".X.....", ".......", ".......", "......."}

    Returns: 7469982

  47. {"..X....", ".......", ".......", "......."}

    Returns: 2942208

  48. {".......", ".......", ".......", "...X..."}

    Returns: 11575062

  49. {".......", ".......", "......X", "......."}

    Returns: 4631904

  50. {".......", ".X.....", ".......", "......."}

    Returns: 8536770

  51. {".......", "..X....", ".......", "......."}

    Returns: 262062

  52. {".......", "...X...", ".......", "......."}

    Returns: 11392074

  53. {"X......", ".......", ".......", ".....X."}

    Returns: 7557426

  54. {".......", ".......", "......X", ".X....."}

    Returns: 5082534

  55. {".......", ".......", ".......", "....X.X"}

    Returns: 11620044

  56. {"X......", ".......", ".......", ".....X."}

    Returns: 7557426

  57. {"......X", "X......", ".......", "......."}

    Returns: 4258728

  58. {".......", "X...X..", ".......", "......."}

    Returns: 12136392

  59. {".X....X", ".......", ".......", "......."}

    Returns: 6394374

  60. {"......X", "...X...", ".......", "......."}

    Returns: 451674

  61. {".....X.", ".......", "....X..", "..X...."}

    Returns: 3878712

  62. {"...X...", ".......", "......X", ".X....."}

    Returns: 7985862

  63. {"..X....", ".......", ".X...X.", "......."}

    Returns: 9644454

  64. {"...X...", ".......", "..X.X..", "......."}

    Returns: 10718244

  65. {".......", "....X..", "......X", ".X....."}

    Returns: 10884168

  66. {"X......", ".......", ".......", "X.X...."}

    Returns: 6434154

  67. {"..X..X.", "X......", "....X..", "......."}

    Returns: 11192274

  68. {"...X...", "X....X.", "..X....", "......."}

    Returns: 11207628

  69. {".X.X...", ".......", "X.X....", "......."}

    Returns: 6120

  70. {".X.....", ".....X.", "X.X....", "......."}

    Returns: 4936284

  71. {"..X.X..", "X......", "....X..", "......X"}

    Returns: 2611908

  72. {".....X.", "X.X....", "......X", "...X..."}

    Returns: 2159478

  73. {"X.X....", ".......", "X.X...X", "....X.."}

    Returns: 1890792

  74. {"......X", "X..X...", "......X", "X.X...."}

    Returns: 1542204

  75. {"X.X.X..", "......X", "...X...", ".X...X."}

    Returns: 3098646

  76. {".......", "X.X.X.X", ".......", "..X.X.X"}

    Returns: 2350080

  77. {"X.X.X.X", ".......", "..X...X", "X...X.."}

    Returns: 3774366

  78. {"X...X.X", "..X....", "X...X.X", "..X...."}

    Returns: 9093312

  79. {".......", ".X...X.", ".......", "......."}

    Returns: 6064416

  80. {".......", ".X.....", ".....X.", "......."}

    Returns: 4126284

  81. {".......", ".....X.", ".X.....", "......."}

    Returns: 4126284

  82. {".......", ".......", ".X...X.", "......."}

    Returns: 6064416

  83. {"..X.."}

    Returns: 6

  84. {"."}

    Returns: 0

  85. {"X.X.X.X", ".......", "X.X.X.X", "......." }

    Returns: 3705444

  86. {".X.....", ".......", "...X...", "......." }

    Returns: 3941820

  87. {"X.", ".." }

    Returns: 6

  88. {"....X.", "......", "X....X", "...X.." }

    Returns: 10044774

  89. {"X..X..X", ".......", "X..X..X", "......." }

    Returns: 1079910


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: