L. Let's count words

Codeforces
IDCF10289L
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Two words $W_1$ and $W_2$ are said to be generated from the same word $W$, if the three words have the same length $L$, and you can read both $W_1$ and $W_2$ from $W$ reading exactly $L$ letters starting at a position in $W$. If while reading from $W$ you get to the end of the word you start again from the first position. For example _rdwo_ and _ordw_ are both generated from the same word _word_, the first one is if you start reading from the third position of the word, the second one is if you start from the second position. A word $W$ is generated from the same word $W$ as you can read the word starting at the first position of it. Given a list of $N$ words, can you find how many different generator words $W$ were used to create the list? The first line of input contains a single integer $N$ ($1 <= N <= 100$), representing the number of words in the list. The second and last line of input contains $N$ strings separated by a space, representing the $N$ words in the list. Each word in the list will contain only lower case letters from the english alphabet and will have no more than $100$ letters. Print a single line with an integer, representing the number of different generator words $W$ that were used to create the list. ## Input The first line of input contains a single integer $N$ ($1 <= N <= 100$), representing the number of words in the list. The second and last line of input contains $N$ strings separated by a space, representing the $N$ words in the list. Each word in the list will contain only lower case letters from the english alphabet and will have no more than $100$ letters. ## Output Print a single line with an integer, representing the number of different generator words $W$ that were used to create the list. [samples]
**Definitions** Let $ T \in \mathbb{Z}^+ $ be the number of test cases. For each test case: - Let $ n, m \in \mathbb{Z}^+ $ denote the dimensions of the board, with $ 5 \leq n, m \leq 10^3 $. - Let $ B \subseteq \{1, \dots, n\} \times \{1, \dots, m\} $ be the set of positions occupied by black stones ($ a_{i,j} = 1 $). - Let $ W \subseteq \{1, \dots, n\} \times \{1, \dots, m\} $ be the set of positions occupied by white stones ($ a_{i,j} = 2 $). - Let $ E = \{ (i,j) \mid a_{i,j} = 0 \} $ be the set of empty positions. **Constraints** 1. $ 1 \leq T \leq 100 $ 2. $ \sum_{\text{test cases}} n \cdot m \leq 10^6 $ 3. $ |B| = |W| $ 4. $ |E| \geq 2 $ 5. Neither black nor white has five-in-a-row in the current position. **Objective** Determine the optimal move for black (to be placed on some $ (x,y) \in E $): - **Win**: If there exists $ (x,y) \in E $ such that placing a black stone at $ (x,y) $ creates a line (horizontal, vertical, or diagonal) of ≥5 consecutive black stones. Among all such moves, choose the lexicographically smallest $ (x,y) $ (min $ x $, then min $ y $). - **Defense**: If no winning move exists, but there exists $ (x,y) \in E $ such that placing a black stone at $ (x,y) $ blocks *all* potential white winning moves in the next turn (i.e., for every $ (u,v) \in E \setminus \{(x,y)\} $, placing white at $ (u,v) $ does *not* create a five-in-a-row). Among all such defensive moves, choose the lexicographically smallest $ (x,y) $. - **Defeated**: If neither a winning nor a defensive move exists.
API Response (JSON)
{
  "problem": {
    "name": "L. Let's count words",
    "description": {
      "content": "Two words $W_1$ and $W_2$ are said to be generated from the same word $W$, if the three words have the same length $L$, and you can read both $W_1$ and $W_2$ from $W$ reading exactly $L$ letters start",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10289L"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Two words $W_1$ and $W_2$ are said to be generated from the same word $W$, if the three words have the same length $L$, and you can read both $W_1$ and $W_2$ from $W$ reading exactly $L$ letters start...",
      "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, m \\in \\mathbb{Z}^+ $ denote the dimensions of the board, with $ 5 \\leq n, m \\leq 10^3 $.  \n...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments