G. Most Common Suffix

Codeforces
IDCF10150G
Time1000ms
Memory512MB
Difficulty
English · Original
Formal · Original
You are given n strings, and q queries. For each query i, your task is to find the most common suffix of length xi, you need to print how common it is. The suffix i (or the ith suffix) of a string is a special case of substring that goes from the ith character of the string up to the last character of the string. For example, the 4th suffix of "_development_" is "_lopment_", the 7th suffix of "_development_" is "_ment_" (0-based indexing). The first line contains an integer T (1 ≤ T ≤ 75), where T is the number of test cases. The first line of each test case contains two integers n and q (1 ≤ n, q ≤ 104), where n is the number of strings, and q is the number of queries. Then n lines follow, each line contains a string s, giving the strings. All strings are non-empty consisting of lowercase English letters. Then q lines follow, each line contains an integer x (1 ≤ x ≤ m), giving the queries. Where m equals the length of the longest string among the given n strings. The total length of strings in each test case does not exceed 105. For each query, print a single line containing the answer. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java. ## Input The first line contains an integer T (1 ≤ T ≤ 75), where T is the number of test cases.The first line of each test case contains two integers n and q (1 ≤ n, q ≤ 104), where n is the number of strings, and q is the number of queries.Then n lines follow, each line contains a string s, giving the strings. All strings are non-empty consisting of lowercase English letters.Then q lines follow, each line contains an integer x (1 ≤ x ≤ m), giving the queries. Where m equals the length of the longest string among the given n strings.The total length of strings in each test case does not exceed 105. ## Output For each query, print a single line containing the answer. [samples] ## Note As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case: - Let $ n, q \in \mathbb{Z} $ denote the number of strings and queries, respectively. - Let $ S = \{s_1, s_2, \dots, s_n\} $ be a set of strings, where each $ s_i $ is a non-empty string over the lowercase English alphabet. - Let $ m = \max_{s_i \in S} |s_i| $ be the length of the longest string. **Constraints** 1. $ 1 \leq T \leq 75 $ 2. For each test case: - $ 1 \leq n, q \leq 10^4 $ - $ 1 \leq |s_i| \leq m $ for all $ s_i \in S $ - $ \sum_{s_i \in S} |s_i| \leq 10^5 $ - For each query $ x $: $ 1 \leq x \leq m $ **Objective** For each query $ x $, compute the maximum frequency among all suffixes of length $ x $ across all strings in $ S $. That is, for each $ x $, define: $$ f_x(t) = \left| \left\{ s \in S \,\middle|\, \text{suffix of } s \text{ of length } x \text{ equals } t \right\} \right| $$ Then output: $$ \max_{t \in \Sigma^x} f_x(t) $$ where $ \Sigma $ is the set of lowercase English letters.
API Response (JSON)
{
  "problem": {
    "name": "G. Most Common Suffix",
    "description": {
      "content": "You are given n strings, and q queries. For each query i, your task is to find the most common suffix of length xi, you need to print how common it is. The suffix i (or the ith suffix) of a string is",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10150G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given n strings, and q queries. For each query i, your task is to find the most common suffix of length xi, you need to print how common it is.\n\nThe suffix i (or the ith suffix) of a string is...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case:  \n- Let $ n, q \\in \\mathbb{Z} $ denote the number of strings and queries, respectively.  \n- Let $ S = \\{s_...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments