Statistics

Problem Statement for "SubRectangles"

Problem Statement

This problem has a non-standard time limit: 5 seconds.

There is a rectangular board divided into H times W square cells. The board is currently empty. Cat Snuke is going to put tokens on some cells. He may only put at most one token onto each cell. When he's finished, each possible subrectangle of dimensions H2 times W2 must contain the same number of tokens.

You are given the ints H, W, H2, and W2. Count valid ways of placing the tokens. Return the answer modulo 1,000,000,007.

Definition

Class:
SubRectangles
Method:
countWays
Parameters:
int, int, int, int
Returns:
int
Method signature:
int countWays(int H, int W, int H2, int W2)
(be sure your method is public)

Constraints

  • H and W will be between 1 and 1,000,000,000, inclusive.
  • H2 and W2 will be between 1 and 4, inclusive.
  • H2 will be less than or equal to H.
  • W2 will be less than or equal to W.

Examples

  1. 2015

    666

    1

    1

    Returns: 2

    Snuke can choose between two valid ways of placing the tokens: Either he puts one token onto each cell, or he leaves all cells empty.

  2. 3

    3

    3

    2

    Returns: 160

    The following picture shows one possible way to put tokens ('o' is a cell with token, '-' is a cell without token): -oo o-- ooo There are two subrectangles with the dimensions 3 rows by 2 columns. Each of these contains four tokens.

  3. 6

    3

    4

    1

    Returns: 346

  4. 10

    20

    3

    3

    Returns: 705820974

  5. 123456789

    987654321

    3

    4

    Returns: 841175976

  6. 1000000000

    1000000000

    4

    4

    Returns: 294775952

  7. 1

    1

    1

    1

    Returns: 2

  8. 1000000000

    1000000000

    1

    1

    Returns: 2

  9. 537538007

    988279542

    1

    1

    Returns: 2

  10. 1000000000

    1000000000

    1

    2

    Returns: 140625003

  11. 215488404

    312949792

    1

    2

    Returns: 501963916

  12. 1000000000

    1000000000

    1

    3

    Returns: 471879292

  13. 76267071

    186092455

    1

    3

    Returns: 117221296

  14. 1000000000

    1000000000

    1

    4

    Returns: 117456091

  15. 314962285

    108777344

    1

    4

    Returns: 576447115

  16. 1000000000

    1000000000

    2

    1

    Returns: 140625003

  17. 903149395

    19050635

    2

    1

    Returns: 482291716

  18. 1000000000

    1000000000

    2

    2

    Returns: 281249995

  19. 934875039

    211306883

    2

    2

    Returns: 848140680

  20. 1000000000

    1000000000

    2

    3

    Returns: 435297829

  21. 642147272

    268452149

    2

    3

    Returns: 741259539

  22. 1000000000

    1000000000

    2

    4

    Returns: 134522251

  23. 576909845

    798879133

    2

    4

    Returns: 973358955

  24. 1000000000

    1000000000

    3

    1

    Returns: 471879292

  25. 549372606

    200904750

    3

    1

    Returns: 819756581

  26. 1000000000

    1000000000

    3

    2

    Returns: 435297829

  27. 641125761

    615824533

    3

    2

    Returns: 538916709

  28. 1000000000

    1000000000

    3

    3

    Returns: 457860648

  29. 87866888

    928280505

    3

    3

    Returns: 107488238

  30. 1000000000

    1000000000

    3

    4

    Returns: 795528520

  31. 547990792

    126071906

    3

    4

    Returns: 652588062

  32. 1000000000

    1000000000

    4

    1

    Returns: 117456091

  33. 679635007

    828842146

    4

    1

    Returns: 793105884

  34. 1000000000

    1000000000

    4

    2

    Returns: 134522251

  35. 965585461

    518373373

    4

    2

    Returns: 229602156

  36. 1000000000

    1000000000

    4

    3

    Returns: 795528520

  37. 982197866

    440553560

    4

    3

    Returns: 292626401

  38. 1000000000

    1000000000

    4

    4

    Returns: 294775952

  39. 658051644

    71464784

    4

    4

    Returns: 984057137

  40. 999999999

    999999999

    4

    4

    Returns: 34247703

  41. 999999999

    999999998

    4

    4

    Returns: 631146518

  42. 999999999

    999999997

    4

    4

    Returns: 275791433

  43. 999999999

    999999996

    4

    4

    Returns: 198330492

  44. 999999998

    999999999

    4

    4

    Returns: 631146518

  45. 999999998

    999999998

    4

    4

    Returns: 361883424

  46. 999999998

    999999997

    4

    4

    Returns: 452755501

  47. 999999998

    999999996

    4

    4

    Returns: 156883944

  48. 999999997

    999999999

    4

    4

    Returns: 275791433

  49. 999999997

    999999998

    4

    4

    Returns: 452755501

  50. 999999997

    999999997

    4

    4

    Returns: 684473377

  51. 999999997

    999999996

    4

    4

    Returns: 860483093

  52. 999999996

    999999999

    4

    4

    Returns: 198330492

  53. 999999996

    999999998

    4

    4

    Returns: 156883944

  54. 999999996

    999999997

    4

    4

    Returns: 860483093

  55. 999999996

    999999996

    4

    4

    Returns: 104707047


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: