Reverse Severer

면접 대비

시간 제한1초메모리 제한2048 MB

요약
문자열 S가 주어질 때, S를 여러 조각으로 나눈 뒤 조각의 순서를 뒤집어 이어 붙여 각 질의 문자열 T를 만들 수 있는지 판정한다.
난이도

보통10점 중 7점

유형
문자열, 동적 계획법, 해시맵, 투 포인터
정답자
아직 제출이 없습니다

문제

You are given a string SS of length NN. There are QQ queries (numbered from 11 to QQ) that you need to answer. For query ii, determine if a string T_iT\_i of length NN, can be obtained by performing the following algorithm from the initial string SS.

  1. First, split the string SS into one or more substrings.
  2. Reverse the order of the substrings.
  3. Concatenate the substrings into a single string.

For instance, you can obtain string SEVERER from string REVERSE by splitting it into R, E, VER, and SE. After reversing the order of the substrings, your substrings will be SE, VER, E, and R. If you concatenate the substrings, then you can obtain string SEVERER.

입력

The first line consists of an integer NN (1≤N≤10,0001 ≤ N ≤ 10\\, 000).

The second line consists of a string SS of length NN.

The third line consists of an integer QQ (1≤Q≤1001 ≤ Q ≤ 100)

Each of the next QQ lines consists of a string T_iT\_i of length NN.

All strings consist of only upper-case letters.

출력

For each query, output a single line containing a string. If string T_iT\_i can be obtained from the algorithm above, output YES. Otherwise, output NO.

예제3

  1. 예제 1

    입력
    7
    REVERSE
    5
    SEVERER
    EVERSER
    REVERSE
    EVEREST
    RESERVE
    
    예상 출력
    YES
    YES
    YES
    NO
    NO
    
  2. 예제 2

    입력
    3
    INC
    6
    INC
    ICN
    NIC
    NCI
    CIN
    CNI
    
    예상 출력
    YES
    NO
    NO
    YES
    YES
    YES
    
  3. 예제 3

    입력
    1
    A
    2
    A
    B
    
    예상 출력
    YES
    NO