The Leaking Robot
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Oh no! Chef’s robot from problem "Reach The Point" (RETPO) has broken up.
It's old oil tank has got leaked, it is leaking oil now.
The robot start doing the following weird moves. While moving it keeps leaving a trace of oil on the path it's been tracing.
Note that in a single step robot will move by one unit in the current direction it is moving.
- Initially the robot is at position (0, 0).
- In the beginning it goes 1 step to the East (i.e. In a single step, its x coordinate will increase by 1 unit.)
- then 2 steps to the North, (i.e. In a single step, its y coordinate will increase by 1 unit.)
- then 3 steps to the West, (i.e. In a single step, its x coordinate will decrease by 1 unit.)
- then 4 steps to the South, (i.e. In a single step, its y coordinate will decrease by 1 unit.)
- then 5 steps to the East,
- and so on.
Thus each time the robot turns 90 degrees anti clockwise, and it will go one more step than before. Please view the following image to
understand the moves. The red line in the example shows the path traced by the robot having traces of oil on it.
Now chef wants to know whether the point (X, Y) will have traces of oil on it or not.
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
For each test case, there is a single line containing two space-separated integers X and Y.
For each test case, output a single line containing “YES” (without quotes) if robot will reach point (X, Y) and “NO” otherwise.
- 1 ≤ T ≤ 100000 = 105
- -1000000000 ≤ X, Y ≤ 1000000000, i.e., -109 ≤ X, Y ≤ 109
Input: 3 3 3 3 5 0 0 Output: YES NO YES
The points (0, 0) and (3, 3) will be having trace of oil while point (3, 5) will not have any trace of oil because point (3, 5) does not lie on the trajectory of robot.
|Tags||ad-hoc aug14 easy witalij_hq|
|Time Limit:||3 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.4, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.