B. Not simply beatiful strings

Codeforces
IDCF955B
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
Let's call a string _adorable_ if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, _ababa_ is _adorable_ (you can transform it to _aaabb_, where the first three letters form a group of _a_\-s and others — a group of _b_\-s), but _cccc_ is not since in each possible consequent partition letters in these two groups coincide. You're given a string _s_. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are _adorable_. Here a subsequence is an arbitrary set of indexes of the string. ## Input The only line contains _s_ (1 ≤ |_s_| ≤ 105) consisting of lowercase latin letters. ## Output Print «_Yes_» if the string can be split according to the criteria above or «_No_» otherwise. Each letter can be printed in arbitrary case. [samples] ## Note In sample case two _zzcxx_ can be split into subsequences _zc_ and _zxx_ each of which is _adorable_. There's no suitable partition in sample case three.
我们称一个字符串为 _adorable_,如果它的字母可以重新排列,使得形成两个连续的、由相同字符组成的组(注意:不同的组必须包含不同的字符)。例如,_ababa_ 是 _adorable_ 的(你可以将其变换为 _aaabb_,其中前三个字母构成一组 #cf_span[a]-s,其余字母构成一组 #cf_span[b]-s),但 _cccc_ 不是,因为在任何可能的连续划分中,这两个组的字母都相同。 给定一个字符串 #cf_span[s]。请判断它是否能被拆分为两个非空子序列,使得这两个子序列形成的字符串都是 _adorable_ 的。这里,子序列是指字符串中任意一组下标。 输入仅一行,包含一个由小写拉丁字母组成的字符串 #cf_span[s] #cf_span[(1 ≤ |s| ≤ 105)]。 如果字符串能按照上述标准拆分,则输出 «_Yes_»,否则输出 «_No_»。 字母可以任意大小写输出。 在第二个样例中,_zzcxx_ 可以被拆分为子序列 _zc_ 和 _zxx_,每个都是 _adorable_ 的。 第三个样例中不存在合适的划分。 ## Input 输入仅一行,包含一个由小写拉丁字母组成的字符串 #cf_span[s] #cf_span[(1 ≤ |s| ≤ 105)]。 ## Output 如果字符串能按照上述标准拆分,则输出 «_Yes_»,否则输出 «_No_»。字母可以任意大小写输出。 [samples] ## Note 在第二个样例中,_zzcxx_ 可以被拆分为子序列 _zc_ 和 _zxx_,每个都是 _adorable_ 的。第三个样例中不存在合适的划分。
**Definitions** Let $ s $ be a string of length $ n \geq 1 $ over the alphabet $ \Sigma = \{a, b, \dots, z\} $. A string $ t $ is *adorable* if there exists a permutation of $ t $ that can be written as $ x^a y^b $, where: - $ x, y \in \Sigma $, $ x \ne y $, - $ a, b \geq 1 $, - $ x^a $ denotes $ a $ consecutive copies of $ x $, - $ y^b $ denotes $ b $ consecutive copies of $ y $. Equivalently, $ t $ is adorable if it contains exactly two distinct characters, and each appears at least once. **Given** A string $ s $ of length $ n $, $ 1 \leq n \leq 10^5 $. **Objective** Determine whether there exists a partition of the indices of $ s $ into two non-empty disjoint subsets $ I_1, I_2 \subset \{1, \dots, n\} $, $ I_1 \cup I_2 = \{1, \dots, n\} $, such that: - The subsequence $ s_{I_1} $ (formed by characters at indices in $ I_1 $) is adorable, - The subsequence $ s_{I_2} $ (formed by characters at indices in $ I_2 $) is adorable. **Output** “Yes” if such a partition exists; “No” otherwise.
Samples
Input #1
ababa
Output #1
Yes
Input #2
zzcxx
Output #2
Yes
Input #3
yeee
Output #3
No
API Response (JSON)
{
  "problem": {
    "name": "B. Not simply beatiful strings",
    "description": {
      "content": "Let's call a string _adorable_ if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For exam",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF955B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Let's call a string _adorable_ if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For exam...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "我们称一个字符串为 _adorable_,如果它的字母可以重新排列,使得形成两个连续的、由相同字符组成的组(注意:不同的组必须包含不同的字符)。例如,_ababa_ 是 _adorable_ 的(你可以将其变换为 _aaabb_,其中前三个字母构成一组 #cf_span[a]-s,其余字母构成一组 #cf_span[b]-s),但 _cccc_ 不是,因为在任何可能的连续划分中,这两个组的字母都相...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ s $ be a string of length $ n \\geq 1 $ over the alphabet $ \\Sigma = \\{a, b, \\dots, z\\} $.  \nA string $ t $ is *adorable* if there exists a permutation of $ t $ that can be writ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments