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

13856번 - Favorite music 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB479624.000%

문제

Al likes music a lot. He has n favorite music fragments he particularly enjoys listening to. It is well known that music can be expressed using notes. For simplicity, we’ll ignore pauses, different note durations and octaves. We’ll assume that a music fragment is just a non-empty sequence of notes (without chords, so no two notes are played at the same time) in the common letter notation:

C, C#, D, D#, E, F, F#, G, G#, A, A#, B.

What is better than listening to some favorite music? Only listening to more favorite music! Unfortunately, Al doesn’t have a lot of time for that. Therefore, he’d like to know how much time does he need to hear a couple of his favorite fragments at a time. These fragments may overlap, but the notes in both of them must go in the same order and without any insertions in between.

입력

The first line contains an integer n (1 ≤ n ≤ 3 × 105 ) – the number of music fragments. Each of the next n lines contains a sequence of notes without spaces describing one fragment. It’s guaranteed that all fragments are different. The total length of the strings representing all the fragments is not greater than 3 × 105 . The next line contains an integer q (1 ≤ q ≤ 105 ) – the number of questions Al has in mind. Each of the next q lines contains two different fragment indices. Fragments are numbered from 1 to n as they appear in the input.

출력

For each question, print on a separate line the minimum time needed to hear both given fragments. Assume that each note lasts for one time interval.

제한

예제 입력 1

3
ABCAB
AC
ACAB
3
1 2
1 3
2 3

예제 출력 1

7
7
4

예제 입력 2

5
EBEBGF#DEEBEBF#GABBEBECBGAAADAEADA
EECAGGECDECBAACDEECAAAFABCAGAAAA
EECAGGECDECBAACDECEFGCGFEFDCDDDD
G#A#CDD#FD#DCA#G#A#CDD#FDD#FGG#A#G#GFD#DD#FGG#A#
GG#A#CDD#DCFD#DGFD#DCA#CDD#FGFD#A#CA#G#GFD#DCC
3
2 3
4 5
5 1

예제 출력 2

64
63
66

힌트

출처

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2016 B번

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

출처

대학교 대회

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

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