
isTeleportation
Teleportation is the theoretical transfer of matter or energy from one point to another without traversing the physical space between them. Teleportation, or the ability to transport a person or object instantly from one place to another, is a technology that could change the course of civilization an alter the destiny of nations.
As of the present day, teleportation has not been implemented in the real world. However, by the development of science and technology, in the 22nd century, people can move by teleporting. A limitation on teleportation is that if a person is located at the coordinate (x, y)
, then he can teleport only to four positions (x + y, y)
, (x - y, y)
, (x, y+x)
or (x, y-x)
.
Given the coordinates (x1, y1)
and (x2, y2)
, check if it is possible for people to move from (x1, y1)
to (x2, y2)
through a series of teleporations.
Example:
- For
a={3, 5, 11, 8}
the result should beisTeleportation(a)=true
.(x1, y1)=(3, 5)
,(x2, y2)=(11, 8)
.(3, 5)
→(3, 3+5)
or(3, 8)
→(3+8, 8)
or(11, 8)
. - For
a={3, 5, 10, 8}
the result should beisTeleportation(a)=false
.(x1, y1)=(3, 5)
,(x2, y2)=(10, 8)
.(3, 5)
→(3, 3+5)
or(3, 8)
→(3+8, 8)
or(11, 8)
not(10, 8)
. You can move it the other way, but in this example the result will still befalse
.
Input/Output:
- [Execution time limit] 0.5s in C++, 3s in Java and C#, 4s in Python, GO and Js
- [Input] array integer a
a.size()=4
-109 ≤ a[i] ≤ 109
- [Output] boolean
returntrue
if it is possible for people to move from(x1, y1)
to(x2, y2)
through a series of teleporations; otherwise, returnfalse
.
Post Comment