A. Links and Pearls

Codeforces
IDCF980A
Time1000ms
Memory256MB
Difficulty
implementationmath
English · Original
Chinese · Translation
Formal · Original
A necklace can be described as a string of links ('_\-_') and pearls ('_o_'), with the last link or pearl connected to the first one. <center>![image](https://espresso.codeforces.com/706e95573748870ca7bf37b28bd1e9a90d37bed9.png)</center>You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace. ## Input The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '_\-_' represents a link and the lowercase English letter '_o_' represents a pearl. ## Output Print "_YES_" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "_NO_". You can print each letter in any case (upper or lower). [samples]
一条项链可以描述为由链节('_-_')和珍珠('_o_')组成的字符串,其中最后一个链节或珍珠与第一个相连。 你可以移除一个链节或一颗珍珠,并将其插入到项链上其他两个现有的链节或珍珠之间(或链节与珍珠之间)。这个过程可以重复任意多次,但你不能丢弃任何部分。 你能否使每两颗相邻珍珠之间的链节数量相等?如果两颗珍珠之间没有其他珍珠,则认为它们是相邻的。 注意,最终的项链必须保持为一个与初始项链长度相同的环形部分。 输入的唯一一行包含一个字符串 $s$($3 lt.eq | s | lt.eq 100$),表示项链,其中连字符 '_-_' 表示链节,小写英文字母 '_o_' 表示珍珠。 如果可以通过重新连接链节和珍珠,使得每两颗相邻珍珠之间的链节数量相等,则输出 "_YES_";否则输出 "_NO_"。 你可以以任意大小写形式输出每个字母。 ## Input 输入的唯一一行包含一个字符串 $s$($3 lt.eq | s | lt.eq 100$),表示项链,其中连字符 '_-_' 表示链节,小写英文字母 '_o_' 表示珍珠。 ## Output 如果可以通过重新连接链节和珍珠,使得每两颗相邻珍珠之间的链节数量相等,则输出 "_YES_";否则输出 "_NO_"。你可以以任意大小写形式输出每个字母。 [samples]
**Definitions** Let $ s \in \{ '-', 'o' \}^n $ be the input string representing the necklace, where $ n = |s| $, $ 3 \leq n \leq 100 $. Let $ p $ be the number of pearls in $ s $, i.e., $ p = |\{ i \mid s[i] = 'o' \}| $. **Constraints** 1. The necklace is circular: indices are taken modulo $ n $. 2. The total number of links is $ \ell = n - p $. 3. $ p \geq 1 $ (since the necklace contains at least one pearl, implied by circularity and non-empty string). **Objective** Determine whether it is possible to rearrange the necklace (via cyclic shifts and reordering of links and pearls, preserving multiset of symbols) such that between every pair of adjacent pearls (in the circular order), there is an equal number of links. That is, does there exist a circular arrangement of $ p $ pearls and $ \ell $ links such that the number of links between each consecutive pair of pearls is constant? **Mathematical Condition** Such an arrangement exists **if and only if** $ p = 0 $ or $ \ell \equiv 0 \pmod{p} $. Since $ p = 0 $ is impossible (as $ |s| \geq 3 $ and the string contains at least one 'o' to form a pearl; if no pearls, problem is vacuous but input guarantees at least one pearl by context), we require: $$ p \geq 1 \quad \text{and} \quad p \mid \ell $$ Equivalently: $$ p \mid (n - p) $$ Thus, output "YES" if $ p \mid (n - p) $, else "NO".
Samples
Input #1
_\-o-o--_
Output #1
YES
Input #2
_\-o---_
Output #2
YES
Input #3
_\-o---o-_
Output #3
NO
Input #4
ooo
Output #4
YES
API Response (JSON)
{
  "problem": {
    "name": "A. Links and Pearls",
    "description": {
      "content": "A necklace can be described as a string of links ('_\\-_') and pearls ('_o_'), with the last link or pearl connected to the first one. <center>![image](https://espresso.codeforces.com/706e95573748870c",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF980A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "A necklace can be described as a string of links ('_\\-_') and pearls ('_o_'), with the last link or pearl connected to the first one.\n\n<center>![image](https://espresso.codeforces.com/706e95573748870c...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "一条项链可以描述为由链节('_-_')和珍珠('_o_')组成的字符串,其中最后一个链节或珍珠与第一个相连。\n\n你可以移除一个链节或一颗珍珠,并将其插入到项链上其他两个现有的链节或珍珠之间(或链节与珍珠之间)。这个过程可以重复任意多次,但你不能丢弃任何部分。\n\n你能否使每两颗相邻珍珠之间的链节数量相等?如果两颗珍珠之间没有其他珍珠,则认为它们是相邻的。\n\n注意,最终的项链必须保持为一个与初始项链长...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ s \\in \\{ '-', 'o' \\}^n $ be the input string representing the necklace, where $ n = |s| $, $ 3 \\leq n \\leq 100 $.  \nLet $ p $ be the number of pearls in $ s $, i.e., $ p = |\\{ ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments