CF1070H.BerOS File Suggestion

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature.

There are nn files on hard drive and their names are f1,f2,…,fnf_1, f_2, \dots, f_n. Any file name contains between 11 and 88 characters, inclusive. All file names are unique.

The file suggestion feature handles queries, each represented by a string ss. For each query ss it should count number of files containing ss as a substring (i.e. some continuous segment of characters in a file name equals ss) and suggest any such file name.

For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 22 (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18".

Polycarp 正在开发一款名为 BerOS 的新操作系统。他请你协助实现文件建议功能。

硬盘上共有 nn 个文件,其文件名分别为 f1,f2,…,fnf_1, f_2, \dots, f_n。任意文件名的长度均为 11 至 88 个字符(含端点)。所有文件名互不相同。

文件建议功能需处理若干查询,每个查询由一个字符串 ss 表示。对于每个查询 ss,该功能应统计包含 ss 作为子串(即文件名中存在一段连续的字符恰好等于 ss)的文件数量,并从中任选一个满足条件的文件名作为建议结果。

例如,若文件名集合为 "read.me"、"hosts"、"ops" 和 "beros.18",而查询字符串为 "os",则匹配的文件数量为 22(有两个文件名包含子串 "os"),建议的文件名可以是 "hosts" 或 "beros.18"。

输入格式

The first line of the input contains integer nn (1≤n≤100001 \le n \le 10000) — the total number of files.

The following nn lines contain file names, one per line. The ii-th line contains fif_i — the name of the ii-th file. Each file name contains between 11 and 88 characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique.

The following line contains integer qq (1≤q≤500001 \le q \le 50000) — the total number of queries.

The following qq lines contain queries s1,s2,…,sqs_1, s_2, \dots, s_q, one per line. Each sjs_j has length between 11 and 88 characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.').

输入的第一行包含一个整数 nn(1≤n≤100001 \le n \le 10000)—— 文件总数。

接下来的 nn 行每行包含一个文件名。第 ii 行包含 fif_i —— 第 ii 个文件的文件名。每个文件名长度为 11 至 88 个字符(含端点)。文件名仅由小写拉丁字母、数字和点号字符('.')组成。任意由有效字符组成的序列均可作为文件名(例如,在 BerOS 系统中,"."、".." 和 "..." 均为合法的文件名)。所有文件名互不相同。

接下来一行包含一个整数 qq(1≤q≤500001 \le q \le 50000)—— 查询总数。

接下来的 qq 行每行包含一个查询字符串 s1,s2,…,sqs_1, s_2, \dots, s_q。每个 sjs_j 的长度为 11 至 88 个字符(含端点),且仅由小写拉丁字母、数字和点号字符('.')组成。

输出格式

Print qq lines, one per query. The jj-th line should contain the response on the jj-th query — two values cjc_j and tjt_j, where

  • cjc_j is the number of matched files for the jj-th query,
  • tjt_j is the name of any file matched by the jj-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any.

输出 qq 行,每行对应一个查询。第 jj 行应包含对第 jj 个查询的响应——两个值 cjc_j 和 tjt_j,其中:

  • cjc_j 表示与第 jj 个查询匹配的文件数量;
  • tjt_j 表示任意一个与第 jj 个查询匹配的文件名。若不存在这样的文件,则输出单个字符 \-;若存在多个匹配文件,则任选其一输出。

输入输出样例

  • 输入#1

    4
    test
    contests
    test.
    .test
    6
    ts
    .
    st.
    .test
    contes.
    st

    输出#1

    1 contests
    2 .test
    1 test.
    1 .test
    0 -
    4 test.

输入解题思路,AI测评打分。不知道怎么写?

首页