#K66322. Tetris Tetromino Fit Checker

    ID: 32395 Type: Default 1000ms 256MiB

Tetris Tetromino Fit Checker

Tetris Tetromino Fit Checker

You are given a grid and a tetromino defined by relative cell positions. The task is to determine whether the tetromino can be placed on the grid at a specified position without overlapping any filled cells.

The grid is an n × m matrix where each cell is either empty (denoted by '.') or blocked (denoted by '#'). The tetromino is given as a set of t relative coordinates.

The tetromino can be placed at position \((x, y)\) if and only if for every tetromino cell at relative offset \((r_i, c_i)\), the cell \((x + r_i, y + c_i)\) satisfies:

$$0 \le x + r_i < n \quad \text{and} \quad 0 \le y + c_i < m \quad \text{and} \quad grid[x + r_i][y + c_i] \ne '#'$$

Print YES if the tetromino can be legally placed, otherwise print NO.

inputFormat

The first line contains two integers \(n\) and \(m\) representing the number of rows and columns of the grid.

The next \(n\) lines each consist of a string of length \(m\) describing the grid. Empty cells are denoted by '.' and blocked cells by '#'.

The following line contains an integer \(t\), the number of tetromino cells.

Then follow \(t\) lines, each with two integers \(r_i\) and \(c_i\) representing the relative positions of the tetromino cells.

The last line contains two integers \(x\) and \(y\) specifying the top-left position where the tetromino is to be placed.

outputFormat

Output a single line: YES if the tetromino can be placed without any conflicts, or NO otherwise.

## sample
5 5
.....
.....
.....
.....
.....
4
0 0
0 1
1 0
1 1
2 2
YES