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

18708번 - Exciting Menus 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 512 MB259940.909%

문제

In a restaurant, given $N$ menus, where the menus are represented by the strings $S^1, \dots , S^N$. Each string $S^i$ is associated with an array $A^i$ (of the same length) of joy levels. In this problem, you should choose a submenu defined by three integers $(i, j, k),ドル where $i$ is the index of one of the menus, and $j, k$ specify a substring of this chosen menu.

We need to find the submenu of the highest quality, where the quality $Q$ is defined by the function:

$$Q(i, j, k) = \text{popularity}(S^i_{j,k}) \cdot A^i_k \cdot |S^i_{j,k}|$$

  • $S^i_{j,k}$ = The substring $[j, k]$ (where $j, k$ are one-based, inclusive) of the string $S^i$.
  • popularity($S^i_{j,k}$) = number of menus (from $S^1, \dots , S^N$) that contain the submenu-string $S^i_{j,k}$ as a prefix.
  • $|S^i_{j,k}|$ is the size of the submenu, which is the length of the substring representing the submenu.
  • $A^i_k$ is the joy level of the submenu ($k$th entry of the $i$th array), please note that the index $j$ is not used here.

Can you find the submenu of the highest quality? Please output the corresponding highest quality of the function $Q$.

입력

The first line of the input contains a single integer $T$ specifying the number of test cases.

Each test case begins with a line containing an integer $N$ (1ドル \le N \le 10^5$) specifying the number of menus in the restaurant.

Then $N$ lines follow, the $i$th line contains a string $S^i$ representing the $i$th menu. All the menus are nonempty strings consisting of lowercase English letters, and the sum of their lengths will not exceed 10ドル^5$ per test case.

Then $N$ lines follow, the $i$th line contains array $A^i,ドル in which Ai has the same length as string $S^i$ and (0ドル \le A^i_k \le 10^9$). The values of each array are space-separated.

출력

For each test case, print a single line containing an integer $Q$ representing the maximum quality corresponding to the best submenu $(i, j, k)$.

제한

예제 입력 1

2
2
aabaa
aa
0 0 0 0 100
0 1
4
bbbaa
aa
aab
aax
0 0 0 0 100
0 0
0 0 0
0 0 0

예제 출력 1

500
600

힌트

The triples corresponding to the answers of the two given cases are $(1, 1, 5)$ and $(1, 4, 5)$.

출처

ICPC > Regionals > Africa and Arab > Arab Collegiate Programming Contest > 2018 Arab Collegiate Programming Contest E번

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

출처

대학교 대회

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

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