#GL0000320. Phủ kín các ô lưới (Grid Covering)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phủ kín các ô lưới (Grid Covering)
Grid Covering
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A room is an -by- grid, indexed from . Prakul starts at cell and can perform two kinds of jump:
- Move rows downward, wrapping around after the last row.
- Move columns rightward, wrapping around after the last column.
He may choose the first move, but thereafter he must alternate the two move types: down, right, down, right, ... or right, down, right, down, ... . The starting cell also counts as visited.
Determine whether there is a choice of first move that lets him visit every one of the cells after finitely many moves.
Input
One line contains four integers .
Output
Print YES if all cells can be visited, and NO otherwise.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
2 2 1 1
Output
YES
Explanation
Starting from , go down to , right to , and down (wrapping) to . All four cells are visited.
Example 2
Input
4 2 2 1
Output
NO
Explanation
The downward jump changes the row by modulo , so only rows and can be reached; rows and remain unvisited.