[Solution] Path Parity CodeChef Solution | CodeChef Problem Solution 2022
You are given an integer . Let be an grid such that for . For example, if the grid looks like:
You start at the top left corner of the grid, i.e, cell . You would like to reach the bottom-right corner, cell . To do so, whenever you are at cell , you can move to either cell or cell provided that the corresponding cell lies within
the grid (more informally, you can make one step down or one step right).
The score of a path you take to reach is the sum of all the numbers on that path.
You are given an integer that is either or . Is there a path reaching such that the parity of its score is ?
Recall that the parity of an integer is the (non-negative) remainder obtained when dividing it by . For example, the parity of is and the parity of is . In other words, an even number has parity and an odd number has parity .
Input Format
- The first line contains a single integer — the number of
- test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers and .
Output Format
- For each test case, output the answer on a new line —
YES
if such a path exists, andNO
otherwise.
Each character of the output may be printed in either uppercase or lowercase, i.e, the strings YES
, yEs
, and yes
will all be treated as identical.
No comments:
Post a Comment