아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Find the vault

시간 제한6초메모리 제한1024 MB

요약
격자에서 알려진 칸만 패턴과 일치하도록 직사각형 금고를 놓을 수 있는 모든 위치를 세어 나열한다.
난이도

보통10점 중 7점

유형
문자열 매칭, 행렬, 비트 연산, 완전 탐색
정답자
아직 제출이 없습니다

문제

Khodislav is playing his favorite roguelike game. Every level of the game is a rectangular grid, and each cell is either empty or containing a wall. Until the player gets near the cell, they have no way of knowing what is in it.

Vault rooms, which are especially valued, can be hidden in such a manner that the player cannot reach them by usual means. To get into such a room, the player must cast a spell that uncovers a portion of cells on that level, as well as the teleportation spell. Luckily, the wiki page of the game contains a layout of the vault, which is rectangular. The vault can be located anywhere in the game level, but its orientation must exactly match the layout on the wiki.

Khodislav has already unlocked a part of the level and is curious as for where the vault can be. Find all possible positions of the top left corner of the vault room that do not contradict what is already known about the level. Note that the vault must fully fit into the level.

입력

The first line contains four integers: RR, CC --- the number of rows and columns in the game level, respectively, and AA, BB --- the number of rows and columns in the vault layout, respectively (1≤R,C≤2,0001 \le R, C \le 2\\,000, 1≤A≤R1 \le A \le R, 1≤B≤C1 \le B \le C).

It is followed by the map of the level: RR lines each containing CC characters. For each cell, one of the three characters is provided:

  • '#' (ASCII 35) --- the cell is wall,
  • '.' (ASCII 46) --- the cell is empty,
  • '_' (ASCII 95) --- the contents of the cell are unknown.

The remaining AA lines describe the vault layout, BB characters per line. For each cell, one of the three characters is provided:

  • '#' (ASCII 35) --- the cell must be wall,
  • '.' (ASCII 46) --- the cell must be empty,
  • '_' (ASCII 95) --- the cell can be anything.

출력

In the first line, print an integer KK --- the number of possible positions of the vault (0≤K≤(R−A+1)⋅(C−B+1)0 \le K \le (R-A+1)\cdot(C-B+1)). In the remaining KK lines, print these positions, one per line. Each position is defined by two space-separated integers uu and vv --- the indices of the row and column in the level where the top left cell of the vault layout is located (1≤u≤R−A+11 \le u \le R-A+1, 1≤v≤C−B+11 \le v \le C-B+1).

The positions must be arranged in the ascending order of uu, and for equal uu --- in the ascending order of vv.

힌트

The illustration to the first sample is given on the next page.

Two possible positions of the vault are shown with bold red frames. In the bottom position, contents of the most of the cells are unknown: only two cells are precisely defined both on the level map and on the vault layout. A structure closely resembling a vault can be seen on the left. However, it does not fully fit the level map without an additional column on the left.

예제2

  1. 예제 1

    입력
    12 12 6 6
    _______###__
    ______##.##_
    ______#...#_
    ___#####.##_
    _###_..###.#
    ##.##......#
    #...#.####_#
    ##.##.._____
    _###_.______
    _____.______
    _____.______
    _____.______
    __###_
    _##.##
    _#...#
    _##.##
    __###_
    ______
    
    예상 출력
    2
    1 6
    7 7
    
  2. 예제 2

    입력
    4 5 2 3
    _____
    _._##
    _._._
    __#__
    _##
    ##.
    
    예상 출력
    0