Connection Status:
Competition Arena > MagicalGirlLevelTwoDivTwo
SRM 514 · 2011-05-25 · by wrong · Simple Math, Simple Search, Iteration
Class Name: MagicalGirlLevelTwoDivTwo
Return Type: String
Method Name: isReachable
Arg Types: (vector<int>, int, int)
Problem Statement

Problem Statement

Magical Girls are girls who have magical powers. They fight against evil witches to protect the Earth.


You, one of the Magical Girls, are at point (0, 0) of the plane. You find another Magical Girl at (x, y) and she seems to be injured. So you decide to go to point (x, y) to help her.


You can move only by n-knight jump. For a positive integer n, the n-knight jump is 8 types of moves. You can go from (0, 0) to (n, 1), (n, -1), (-n, 1), (-n, -1), (1, n), (-1, n), (1, -n) or (-1, -n) by using n-knight jump once.


You are given a int[] jumpTypes containing the valid n-knight jumps you can perform. You can only use an n-knight jump if jumpTypes contains n. Return "YES" if you can reach (x, y) with the n-knight jumps of given numbers. Otherwise return "NO" (all quotes for clarity). You can use each n-knight jump as many times as you want.

Constraints

  • jumpTypes will contain between 1 and 10 elements, inclusive.
  • Each element of jumpTypes will be between 1 and 30, inclusive.
  • All elements of jumpTypes will be distinct.
  • x and y will each be between -30 and 30, inclusive.
Examples
0)
{2}
5
4
Returns: "YES"

(0, 0) -> (2, 1) -> (4, 2) -> (5, 4).

1)
{3}
5
4
Returns: "NO"
2)
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
-30
27
Returns: "YES"
3)
{29}
29
0
Returns: "NO"
4)
{1,3,5,7,9,11,13,15,17,19}
29
30
Returns: "NO"

Submissions are judged against all 117 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class MagicalGirlLevelTwoDivTwo with a public method string isReachable(vector<int> jumpTypes, int x, int y) · 117 test cases · 2 s / 256 MB per case

Submitting as anonymous