Word Search

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

요약
작은 2차원 격자 패턴이 큰 격자 안에서 나타나는 모든 위치를 찾아, 일치하는 칸은 원래 문자를 남기고 나머지는 마침표로 바꿔 출력한다.
난이도

보통10점 중 7점

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

문제

Find parts of a 2d grid matching a 2d word.

입력

  • One line containing the number of rows and columns in the search key, r_kr\_k and c_kc\_k (1≤r,c≤20001 \le r, c \le 2000).
  • r_kr\_k further lines, each containing c_kc\_k Latin characters comprising a row of the search key.
  • One line containing the number of rows and columns in the haystack, r_hr\_h and c_hc\_h (r_k≤r_h≤2000r\_k \le r\_h \le 2000, c_k≤c_h≤2000c\_k \le c\_h \le 2000).
  • r_hr\_h further lines, each containing c_hc\_h Latin characters comprising a row of the search key.

출력

Illustrate the matching areas of the haystack by printing a grid of the same size. In locations that are part of at least one match, print the original character from the haystack. In other cases, print a full-stop "." character.

예제4

  1. 예제 1

    입력
    3 3
    ghi
    lmn
    qrs
    5 5
    abcde
    fghij
    klmno
    pqrst
    uvwxy
    
    예상 출력
    .....
    .ghi.
    .lmn.
    .qrs.
    .....
    
  2. 예제 2

    입력
    1 2
    ab
    6 4
    abba
    baab
    abba
    baab
    abba
    baab
    
    예상 출력
    ab..
    ..ab
    ab..
    ..ab
    ab..
    ..ab
    
  3. 예제 3

    입력
    4 1
    n
    a
    n
    a
    7 6
    ananan
    nanana
    ananan
    nanana
    ananan
    nanana
    batman
    
    예상 출력
    .n.n.n
    nanana
    ananan
    nanana
    ananan
    .a.ana
    ....a.
    
  4. 예제 4

    입력
    2 2
    oo
    oo
    5 5
    xoooo
    oxooo
    ooxoo
    oooxo
    oooox
    
    예상 출력
    ..ooo
    ..ooo
    oo.oo
    ooo..
    ooo..