Statistics

Problem Statement for "Superking"

Problem Statement

We have an infinite chess board, and a new type of chess piece called a "superking". It can perform two types of moves:

  • Type-1: the normal king move - i.e., a move to a neighboring square in any of the eight directions horizontal, vertical or diagonal.
  • Type-2: a move two squares to the left, right, up or down.

The superking begins at some square in the infinite board and performs type1 Type-1 moves and type2 Type-2 moves. Return the number of possible squares that the superking can reach after performing these moves.

Definition

Class:
Superking
Method:
squares
Parameters:
int, int
Returns:
long
Method signature:
long squares(int type1, int type2)
(be sure your method is public)

Constraints

  • type1 and type2 will be between 0 and 100000000 (108), inclusive.

Examples

  1. 0

    0

    Returns: 1

    No moves are made, superking remains at the starting square.

  2. 1

    0

    Returns: 8

    After one Type-1 move (normal king move), the superking can land in one of the 8 neighboring squares.

  3. 0

    1

    Returns: 4

    After one Type-2 move, the superking lands in one of the four squares at a distance of 2 from the starting square (to the left, right, up or down).

  4. 1

    2

    Returns: 60

    Let's assume that the superking starts at the red square at the center of the board shown below. After one Type-2 move, the superking can land in one of the blue squares. After the second Type-2 move, the superking can land in one of the red squares. After a final Type-1 move, the superking can land in any square neighboring a red square, i.e., one of the green squares. These are the possible final landing squares for the king after 1 Type-1 and 2 Type-2 moves, 60 in total (note that it is not important in which order we make the moves; here, we first did the two Type-2 moves and then the Type-1 move).

  5. 31

    17

    Returns: 14713

  6. 24

    45

    Returns: 35881

  7. 100000000

    100000000

    Returns: 280000000400000001

    The maximum return value.

  8. 0

    100000000

    Returns: 10000000200000001

  9. 100000000

    0

    Returns: 40000000400000001

  10. 0

    2

    Returns: 9

  11. 0

    10

    Returns: 121

  12. 1

    1

    Returns: 28

  13. 1

    5

    Returns: 228

  14. 1

    100000000

    Returns: 60000001400000008

  15. 2

    0

    Returns: 25

  16. 2

    1

    Returns: 65

  17. 2

    2

    Returns: 121

  18. 2

    7

    Returns: 641

  19. 2

    100000000

    Returns: 80000003200000025

  20. 3

    0

    Returns: 49

  21. 3

    1

    Returns: 105

  22. 3

    2

    Returns: 177

  23. 3

    3

    Returns: 265

  24. 100000000

    1

    Returns: 40000002000000009

  25. 100000000

    2

    Returns: 40000003600000033

  26. 100000000

    3

    Returns: 40000005200000073

  27. 5

    138

    Returns: 163513

  28. 20

    46761

    Returns: 17507694169

  29. 57120

    5183

    Returns: 18002761353

  30. 7706765

    1121940

    Returns: 385991379582361

  31. 2

    288491

    Returns: 665825688385

  32. 24975

    337

    Returns: 2630676153

  33. 8

    34539059

    Returns: 9543577193843689

  34. 4726

    79

    Returns: 95382801

  35. 27

    6

    Returns: 5905

  36. 1

    80

    Returns: 39528

  37. 76

    3772763

    Returns: 113874512936569

  38. 673726

    214

    Returns: 1817936791401

  39. 9247633

    963

    Returns: 342217396349505

  40. 76207

    86

    Returns: 23335252225

  41. 5

    23764455

    Returns: 4517996472732721

  42. 1045420

    318946

    Returns: 10520348931729

  43. 5544

    352

    Returns: 155180961

  44. 94434984

    35

    Returns: 35671918073661801

  45. 26

    5

    Returns: 5089

  46. 27483522

    3

    Returns: 3021377355241153

  47. 56

    44

    Returns: 67681

  48. 4090

    488

    Returns: 100768633

  49. 20

    2651

    Returns: 57072409

  50. 26252026

    10499

    Returns: 2761086383594401

  51. 46976

    241482

    Returns: 656837351713

  52. 2120287

    99

    Returns: 17985834943641

  53. 26674

    1790

    Returns: 3635691961

  54. 579

    5

    Returns: 1389801

  55. 308

    109

    Returns: 1012889

  56. 3104

    18

    Returns: 39448225


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: