E. Text Editor

Codeforces
IDCF10146E
Time1000ms
Memory512MB
Difficulty
English · Original
Formal · Original
One of the most useful tools nowadays are text editors, their use is so important that the Unique Natural Advanced Language (UNAL) organization has studied many of the benefits working with them. They are interested specifically in the feature "find", that option looks when a pattern occurs in a text, furthermore, it counts the number of times the pattern occurs in a text. The tool is so well designed that while writing each character of the pattern it updates the number of times that the corresponding prefix of the total pattern appears on the text. Now the UNAL is working with the editor, finding patterns in some texts, however, they realize that many of the patterns appear just very few times in the corresponding texts, as they really want to see more number of appearances of the patterns in the texts, they put a lower bound on the minimum number of times the pattern should be found in the text and use only prefixes of the original pattern. On the other hand, the UNAL is very picky about language, so they will just use the largest non-empty prefix of the original pattern that fit into the bound. The first line contains the text A (1 ≤ |A| ≤  105) The second line contains the original pattern B (1 ≤ |B| ≤  |A|) The third line contains an integer n (1 ≤ n ≤  |A|) - the minimum number of times a pattern should be found on the text. A single line, with the prefix of the original pattern used by the UNAL, if there is no such prefix then print "IMPOSSIBLE" (without the quotes) ## Input The first line contains the text A (1 ≤ |A| ≤  105) The second line contains the original pattern B (1 ≤ |B| ≤  |A|) The third line contains an integer n (1 ≤ n ≤  |A|) - the minimum number of times a pattern should be found on the text. ## Output A single line, with the prefix of the original pattern used by the UNAL, if there is no such prefix then print "IMPOSSIBLE" (without the quotes) [samples]
**Definitions** Let $ A \in \Sigma^* $ be the text string. Let $ B \in \Sigma^* $ be the original pattern string, with $ |B| \leq |A| $. Let $ n \in \mathbb{Z}^+ $ be the minimum required occurrence bound. For each $ k \in \{1, 2, \dots, |B|\} $, define $ B_k $ as the prefix of $ B $ of length $ k $: $$ B_k = B[1..k] $$ Let $ f(k) $ denote the number of occurrences of $ B_k $ as a substring in $ A $. **Constraints** 1. $ 1 \leq |A| \leq 10^5 $ 2. $ 1 \leq |B| \leq |A| $ 3. $ 1 \leq n \leq |A| $ **Objective** Find the largest $ k \in \{1, 2, \dots, |B|\} $ such that $ f(k) \geq n $. If such a $ k $ exists, output $ B_k $. Otherwise, output "IMPOSSIBLE".
API Response (JSON)
{
  "problem": {
    "name": "E. Text Editor",
    "description": {
      "content": "One of the most useful tools nowadays are text editors, their use is so important that the Unique Natural Advanced Language (UNAL) organization has studied many of the benefits working with them.  Th",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10146E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "One of the most useful tools nowadays are text editors, their use is so important that the Unique Natural Advanced Language (UNAL) organization has studied many of the benefits working with them. \n\nTh...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ A \\in \\Sigma^* $ be the text string.  \nLet $ B \\in \\Sigma^* $ be the original pattern string, with $ |B| \\leq |A| $.  \nLet $ n \\in \\mathbb{Z}^+ $ be the minimum required occurr...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments