Logo
(追記) (追記ここまで)

13402번 - Hidden Anagrams 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
10 초 512 MB32712510846.957%

문제

An anagram is a word or a phrase that is formed by rearranging the letters of another. For instance, by rearranging the letters of “William Shakespeare,” we can have its anagrams “I am a weakish speller,” “I’ll make a wise phrase,” and so on. Note that when A is an anagram of B, B is an anagram of A.

In the above examples, differences in letter cases are ignored, and word spaces and punctuation symbols are freely inserted and/or removed. These rules are common but not applied here; only exact matching of the letters is considered.

For two strings s1 and s2 of letters, if a substring s'1 of s1 is an anagram of a substring s'2 of s2, we call s'1 a hidden anagram of the two strings, s1 and s2. Of course, s'2 is also a hidden anagram of them.

Your task is to write a program that, for given two strings, computes the length of the longest hidden anagrams of them.

Suppose, for instance, that “anagram” and “grandmother” are given. Their substrings “nagr” and “gran” are hidden anagrams since by moving letters you can have one from the other. They are the longest since any substrings of “grandmother” of lengths five or more must contain “d” or “o” that “anagram” does not. In this case, therefore, the length of the longest hidden anagrams is four. Note that a substring must be a sequence of letters occurring consecutively in the original string and so “nagrm” and “granm” are not hidden anagrams.

입력

The input consists of a single test case in two lines.

s1
s2

s1 and s2 are strings consisting of lowercase letters (a through z) and their lengths are between 1 and 4000, inclusive.

출력

Output the length of the longest hidden anagrams of s1 and s2. If there are no hidden anagrams, print a zero.

제한

예제 입력 1

anagram
grandmother

예제 출력 1

4

예제 입력 2

williamshakespeare
iamaweakishspeller

예제 출력 2

18

예제 입력 3

aaaaaaaabbbbbbbb
xxxxxabababxxxxxabab

예제 출력 3

6

예제 입력 4

abababacdcdcd
efefefghghghghgh

예제 출력 4

0

힌트

출처

ICPC > Regionals > Asia Pacific > Japan > Asia Regional Contest 2016 in Tsukuba D번

Camp > Petrozavodsk Programming Camp > Winter 2017 > Day 8: Japanese Contest D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /