C. K-Dominant Character

Codeforces
IDCF888C
Time2000ms
Memory256MB
Difficulty
binary searchimplementationtwo pointers
English · Original
Chinese · Translation
Formal · Original
You are given a string _s_ consisting of lowercase Latin letters. Character _c_ is called _k_\-dominant iff each substring of _s_ with length at least _k_ contains this character _c_. You have to find minimum _k_ such that there exists at least one _k_\-dominant character. ## Input The first line contains string _s_ consisting of lowercase Latin letters (1 ≤ |_s_| ≤ 100000). ## Output Print one number — the minimum value of _k_ such that there exists at least one _k_\-dominant character. [samples]
给定一个由小写拉丁字母组成的字符串 #cf_span[s]。字符 #cf_span[c] 被称为 #cf_span[k]-主导的,当且仅当 #cf_span[s] 的每个长度至少为 #cf_span[k] 的子串都包含该字符 #cf_span[c]。 你需要找到最小的 #cf_span[k],使得存在至少一个 #cf_span[k]-主导的字符。 第一行包含一个由小写拉丁字母组成的字符串 #cf_span[s](#cf_span[1 ≤ |s| ≤ 100000])。 请输出一个数字——存在至少一个 #cf_span[k]-主导字符的最小 #cf_span[k] 值。 ## Input 第一行包含一个由小写拉丁字母组成的字符串 #cf_span[s](#cf_span[1 ≤ |s| ≤ 100000])。 ## Output 请输出一个数字——存在至少一个 #cf_span[k]-主导字符的最小 #cf_span[k] 值。 [samples]
Let $ s $ be a string of length $ n \geq 1 $ over the alphabet $ \Sigma = \{a, b, \dots, z\} $. For a character $ c \in \Sigma $ and an integer $ k \geq 1 $, define $ c $ to be **$ k $-dominant** if every contiguous substring of $ s $ of length $ \geq k $ contains at least one occurrence of $ c $. Define the set: $$ K = \left\{ k \in \mathbb{Z}^+ \mid \exists\, c \in \Sigma \text{ such that } c \text{ is } k\text{-dominant} \right\} $$ Find: $$ \min K $$
Samples
Input #1
abacaba
Output #1
2
Input #2
zzzzz
Output #2
1
Input #3
abcde
Output #3
3
API Response (JSON)
{
  "problem": {
    "name": "C. K-Dominant Character",
    "description": {
      "content": "You are given a string _s_ consisting of lowercase Latin letters. Character _c_ is called _k_\\-dominant iff each substring of _s_ with length at least _k_ contains this character _c_. You have to fin",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF888C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a string _s_ consisting of lowercase Latin letters. Character _c_ is called _k_\\-dominant iff each substring of _s_ with length at least _k_ contains this character _c_.\n\nYou have to fin...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "给定一个由小写拉丁字母组成的字符串 #cf_span[s]。字符 #cf_span[c] 被称为 #cf_span[k]-主导的,当且仅当 #cf_span[s] 的每个长度至少为 #cf_span[k] 的子串都包含该字符 #cf_span[c]。\n\n你需要找到最小的 #cf_span[k],使得存在至少一个 #cf_span[k]-主导的字符。\n\n第一行包含一个由小写拉丁字母组成的字符串 #c...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ s $ be a string of length $ n \\geq 1 $ over the alphabet $ \\Sigma = \\{a, b, \\dots, z\\} $.\n\nFor a character $ c \\in \\Sigma $ and an integer $ k \\geq 1 $, define $ c $ to be **$ k $-dominant** if ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments