Stringology

면접 대비

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

요약
s의 각 접두사에 t를 이어 붙인 문자열에 대해, s의 진접두사이면서 그 접미사인 가장 긴 길이를 모두 구한다.
난이도

어려움10점 중 8점

유형
문자열, 문자열 매칭, 누적 합
정답자
아직 제출이 없습니다

문제

For a string u=u_1…u_nu = u\_1 \dots u\_n, Bobo denotes the prefix u_1…u_iu\_1 \dots u\_i by pre(u,i)\mathrm{pre}(u, i). Similarly, he denotes the suffix u_n−i+1…u_nu\_{n - i + 1} \dots u\_n by suf(u,i)\mathrm{suf}(u, i). In particular, pre(u,0)\mathrm{pre}(u, 0) and suf(u,0)\mathrm{suf}(u, 0) are empty strings.

For two strings u=u_1…u_nu = u\_1 \dots u\_n and v=v_1…v_mv = v\_1 \dots v\_m, Bobo denotes the concatenation u_1…u_nv_1…v_mu\_1 \dots u\_n v\_1 \dots v\_m by u+vu + v. Also, presuf(u,v)=max⁡i∣i<n and i≤m and pre(u,i)=suf(v,i).\mathrm{presuf}(u, v) = \max\\{i \mid i < n \text{ and } i \leq m \text{ and } \mathrm{pre}(u, i) = \mathrm{suf}(v, i) \\}\text{.}

Given two strings s=s_1…s_ns = s\_1 \dots s\_n and t=t_1…t_mt = t\_1 \dots t\_m, let f(i)=presuf(s,pre(s,i)+t)f(i) = \mathrm{presuf}(s, \mathrm{pre}(s, i) + t). Find the value of f(0),…,f(n−1)f(0), \dots, f(n - 1).

입력

The input consists of several test cases terminated by end-of-file. For each test case,

The first line contains a string s_1…s_ns\_1 \dots s\_n.

The second line contains a string t_1…t_mt\_1 \dots t\_m.

출력

For each test case, output nn integers which denote f(0),…,f(n−1)f(0), \dots, f(n - 1).

제한

  • 1≤n,m≤1061 \leq n, m \leq 10^6
  • s_i∈a,…,zs\_i \in \\{a, \dots, z\\} for each 1≤i≤n1 \leq i \leq n
  • t_i∈a,…,zt\_i \in \\{a, \dots, z\\} for each 1≤i≤m1 \leq i \leq m
  • In each input, the sum of max⁡(n,m)\max(n, m) ≤106\leq 10^6.

힌트

For the second case, f(4)=presuf(s,pre(s,4)+t)=presuf(f(4) = \mathrm{presuf}(s, \mathrm{pre}(s, 4) + t) = \mathrm{presuf}(ababa,, abab++a)=presuf() = \mathrm{presuf}(ababa,, ababa)).

iipre(ababa,i)\mathrm{pre}(\mathtt{ababa}, i)suf(ababa,i)\mathrm{suf}(\mathtt{ababa}, i)
00(an empty string)(an empty string)
11a\mathtt{a}a\mathtt{a}
22ab\mathtt{ab}ba\mathtt{ba}
33aba\mathtt{aba}aba\mathtt{aba}
44abab\mathtt{abab}baba\mathtt{baba}

Therefore, f(4)=3f(4) = 3.

예제1

  1. 예제 1

    입력
    aaa
    a
    ababa
    a
    ab
    cd
    
    예상 출력
    1 2 2
    1 1 3 1 3
    0 0