[ABC315D] Magical Cookies
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
[ABC315D] Magical Cookies
题面翻译
给出 的地图,不断进行以下操作:
- 选定某行,若这行字母数 ,并且全是相同的,将所有这些字母标记。
- 选定某列,若这列字母数 ,并且全是相同的,将所有这些字母标记。
- 把目前标记的字母删除,若无删除,结束操作,否则重新跳回操作 1。
。求最后操作完成后还剩多少个字母。
题目描述
There are H×W cookies in H rows and W columns. The color of the cookie at the i-row from the top and j-th column from the left is represented by a lowercase English letter ci,j.
We will perform the following procedure.
- For each row, perform the following operation: if there are two or more cookies remaining in the row and they all have the same color, mark them.
- For each column, perform the following operation: if there are two or more cookies remaining in the column and they all have the same color, mark them.
- If there are any marked cookies, remove them all and return to 1; otherwise, terminate the procedure.
Find the number of cookies remaining at the end of the procedure.
输入格式
输入格式如下:
输出格式
输出一个整数表示最后的答案。
样例 #1
样例输入 #1
4 3
aaa
aaa
abc
abd
样例输出 #1
2
样例 #2
样例输入 #2
2 5
aaaaa
abcde
样例输出 #2
4
样例 #3
样例输入 #3
3 3
ooo
ooo
ooo
样例输出 #3
0
提示
数据范围
- 是小写英文字母
样例解释1
按以下顺序进行操作。 - 1. 操作1, 行所有字母被标记。 - 2. 操作2, 列所有字母被标记。 - 3. 操作3,将所有被标记字母删除。 用"."来替代被删除的字母,可以得到矩阵变成了: ... ... .bc .bd
- 1. 操作1,没有字母被标记。 - 2. 操作2, 列所有字母被标记。 - 3. 将所有被标记字母删除。 用"."来替代被删除的字母,可以得到矩阵变成了: ... ... ..c ..d
- 1.操作1,没有字母被标记。 - 2. 操作2,没有字母被标记。 - 3. 操作3,没有字母被标记,所以没有字母被删除。最終剩下 个字母。
9月19日周二晚上集训赛
- Status
- Done
- Rule
- IOI
- Problem
- 8
- Start at
- 2023-9-19 19:00
- End at
- 2023-9-19 21:00
- Duration
- 2 hour(s)
- Host
- Partic.
- 30