[Solution] Gritty Grid CodeChef Solution 2022 | Solution CodeChef
Problem
Alice and Bob are trapped in a grid having rows and columns. Alice is currently at cell and Bob is at cell and they both want to meet each other at any common cell. But they have some restrictions in the way they can move and meet:
A step is defined as moving to an adjacent cell from the current cell that the person is in. So in a single step, if a person is at they may move to any one of the following cells, provided that they are inside the grid's boundaries - , , , .
A move for Alice is defined to be exactly steps. And a move for Bob is defined to be exactly steps.
They can only meet at the common cell after Alice has just completed her move i.e. they should not meet in the middle of anyone's move or at the end of Bob's move. The first time that they meet should be right after a move of Alice, and they stop moving after that.
Alice makes a move first, then Bob makes a move, and they alternate like this.
Alice and Bob want to know if it is possible to meet with these restrictions. Please help Alice and Bob by telling them whether they would be able to meet each other if they stick to these restrictions.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of a single line of input containing four integers: , , and denoting the number of rows, number of columns, number of steps in Alice's one move and the number of steps in Bob's one move respectively.
Output Format
For each test case, output in a single line if they would be able to meet each other at a common cell, else output .
You may print each character of the string in uppercase or lowercase (for example, the strings , , and will all be treated as identical).
Explanation:
Test case 1: Alice is initially at , and Bob is at . In Alice's first move, she has to take steps - she can choose to go from . And so at the end of Alice's first move, Alice and Bob meet, and they stop. So the answer is Yes.
Test case 2: Alice is initially at , and Bob is at . In Alice's first move, she has to take step - she can choose to go from , or . Similarly for Bob. But you can check that no matter what they do, they can't coordinate in such a way that they meet only after Alice's move. So the answer is No.
Test case 3: Alice is initially at , and Bob is at . In Alice's first move, she has to take step - she can choose to go from . Then in Bob's move, he has to take steps - he can choose to go from . Then in Alice's second move, she can choose to go from . And so at the end of Alice's second move, Alice and Bob meet, and they stop. So the answer is Yes.
Test case 4: Alice is initially at , and Bob is at . In Alice's first move, she has to take steps - she can choose to go from . And so at the end of Alice's first move, Alice and Bob meet, and they stop. So the answer is Yes.
No comments:
Post a Comment