B. Singhal and Equality

Codeforces
IDCF10276B
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
_If you want to practice topicwise questions in the ladder way like a2oj , do register on my site *http://codedigger.tech* after the contest. Here you will get Handpicked Topicwise Questions from codeforces, codechef, uva and spoj for your better practice. Best of Luck._ Singhal loves Equality. He has a string $S$ consisting of lowercase English Letters. He wants to equalize the frequency of all distinct characters in his string $S$. He can do the following operation any number of times: pick any single character in the string and replace with another lowercase English alphabet. He wants to perform minimum number of operations to equalize the frequency of distinct characters. Frequency of a character is number of times it appear in the string. The first line contains a single integer $t (1 <= t <= 10^5)$ — the number of test cases in the input. Then $t$ test cases follow. Each query contains a single string consisting of lowercase English letters $S (1 <= | S | <= 10^5)$. $| S |$ is the length of the string. It is guaranteed that the total sum of $| S |$ is at most $10^5$. Print $t$ answers to the test cases. Each answer must be consisting of single integer — the minimum number of operations required to equalize the frequency of distinct characters of string. In the first query — We can replace letter $b arrow.r a$ to form _aaa_. Now frequency of all distinct character is same i.e. $3$ or another possibility is replace one $a arrow.r c$ to form _abc_. In this case frequency is $1$. In the second query — Frequency of all distinct character is Same i.e. $2$. No need to apply operation. ## Input The first line contains a single integer $t (1 <= t <= 10^5)$ — the number of test cases in the input. Then $t$ test cases follow.Each query contains a single string consisting of lowercase English letters $S (1 <= | S | <= 10^5)$. $| S |$ is the length of the string. It is guaranteed that the total sum of $| S |$ is at most $10^5$. ## Output Print $t$ answers to the test cases. Each answer must be consisting of single integer — the minimum number of operations required to equalize the frequency of distinct characters of string. [samples] ## Note In the first query — We can replace letter $b arrow.r a$ to form _aaa_. Now frequency of all distinct character is same i.e. $3$ or another possibility is replace one $a arrow.r c$ to form _abc_. In this case frequency is $1$.In the second query — Frequency of all distinct character is Same i.e. $2$. No need to apply operation.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case: - Let $ n, m, Q \in \mathbb{Z} $ denote the grid dimensions and number of queries. - Let $ G \in \{ \texttt{'}.\texttt{'} , \texttt{'}#\texttt{'} \}^{n \times m} $ be the grid, where $ G[i][j] = \texttt{'}#\texttt{'} $ means dry, $ \texttt{'}.\texttt{'} $ means wet. - Let $ \mathcal{Q} = \{ (t_i, x_i, y_i) \mid i \in \{1, \dots, Q\} \} $ be the sequence of queries, where $ t_i \in \{1, 2\} $. **Constraints** 1. $ 1 \le T \le 1000 $ 2. $ 1 \le n, m, Q \le 10^3 $ 3. $ \sum \max(n, m, Q) \le 2 \times 10^4 $ over all test cases 4. For each query: - If $ t_i = 1 $: toggle state of cell $ (x_i, y_i) $ (dry ↔ wet) - If $ t_i = 2 $: compute maximum area of axis-aligned $ a \times b $ rectangular frame (width 1) with dry boundary only, where $ a \ge 1, b \ge 1 $ **Objective** For each query with $ t_i = 2 $: Compute $$ \max \left\{ a \cdot b \ \middle|\ \begin{array}{c} 1 \le a \le n,\ 1 \le b \le m, \\ \text{the frame of } a \times b \text{ rectangle has all boundary cells dry} \end{array} \right\} $$ If no such frame exists, output $ 0 $.
API Response (JSON)
{
  "problem": {
    "name": "B. Singhal and Equality",
    "description": {
      "content": "_If you want to practice topicwise questions in the ladder way like a2oj , do register on my site *http://codedigger.tech* after the contest. Here you will get Handpicked Topicwise Questions from code",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10276B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "_If you want to practice topicwise questions in the ladder way like a2oj , do register on my site *http://codedigger.tech* after the contest. Here you will get Handpicked Topicwise Questions from code...",
      "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, Q \\in \\mathbb{Z} $ denote the grid dimensions and number of queries.  \n- Let $ G \\in \\{ \\t...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments