Ari's Clever Portal Trip
Time limit1sMemory limit512 MB
Simulate Ari's zigzag walk from row 1 to the portal at (N, M) and report whether the path passes through the minion cell (Sr, Sc).
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
To hunt the boss monster, Ari has to take the portal in the wilderness. However, the wilderness also holds one minion monster, the right arm of the boss monster, which tries to stop Ari from reaching the portal. The wilderness is an grid with rows and columns. The top left cell is and the bottom right cell is . Ari starts at , the minion monster is at , and the portal is at . The minion monster is never located at .
The minion monster cannot move from its starting cell, so it cannot block Ari directly. Instead, it casts a spell on Ari's movement:
- Ari moves either left or right.
- If Ari is moving left, Ari must go to the left end of the row. If Ari is moving right, Ari must go to the right end of the row. When Ari reaches the end of a row, Ari moves down one row.
- When Ari moves down, the direction becomes the opposite of the direction in the row above.
For example, when the grid has 5 rows and 6 columns and Ari starts at , Ari's paths for each direction are shown below.
Under these restrictions, Ari may meet the minion monster, or may go straight to the portal without meeting it. Before Ari leaves, check whether Ari meets the minion monster.
Input
The first line contains two integers and , the size of the wilderness. ()
The second line contains an integer (), the column where Ari starts, and Ari's direction . is either 0 or 1. If is 0, Ari moves left. If is 1, Ari moves right.
The third line contains two integers () and (), the position of the minion monster.
Output
If Ari can reach the portal without meeting the minion monster, print "YES!" on the first line. If Ari meets the minion monster, print "NO...".

