B. African Crossword

Codeforces
IDCF90B
Time2000ms
Memory256MB
Difficulty
implementationstrings
English · Original
Chinese · Translation
Formal · Original
An African crossword is a rectangular table _n_ × _m_ in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously. When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem. You are suggested to solve an African crossword and print the word encrypted there. ## Input The first line contains two integers _n_ and _m_ (1 ≤ _n_, _m_ ≤ 100). Next _n_ lines contain _m_ lowercase Latin letters each. That is the crossword grid. ## Output Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter. [samples]
非洲填字游戏是一个大小为 $n × m$ 的矩形表格。表格中的每个单元格恰好包含一个字母。该表格(也称为网格)包含一个需要解密的加密单词。 要解谜该填字游戏,你需要划掉所有在行和列中重复出现的字母。换句话说,一个字母只有在对应的行或列中至少还有一个与之完全相同的字母时,才被划掉。此外,所有这样的字母将同时被划掉。 当所有重复的字母都被划掉后,我们将剩余的字母按顺序写成一个字符串。位置较高的字母排在位置较低的字母之前;如果字母在同一行中,则靠左的字母优先。由此得到的单词即为问题的答案。 请你解出这个非洲填字游戏,并打印出其中加密的单词。 第一行包含两个整数 $n$ 和 $m$($1 ≤ n, m ≤ 100$)。接下来的 $n$ 行每行包含 $m$ 个小写拉丁字母,即填字游戏的网格。 请在一行中打印出加密的单词。保证答案至少包含一个字母。 ## Input 第一行包含两个整数 $n$ 和 $m$($1 ≤ n, m ≤ 100$)。接下来的 $n$ 行每行包含 $m$ 个小写拉丁字母,即填字游戏的网格。 ## Output 请在一行中打印出加密的单词。保证答案至少包含一个字母。 [samples]
Let $ G $ be an $ n \times m $ matrix over the alphabet $ \Sigma $ (lowercase Latin letters), where $ G[i][j] $ denotes the letter at row $ i $, column $ j $. Define: - For each cell $ (i, j) $, let $ r_i $ be the multiset of letters in row $ i $: $ r_i = \{ G[i][k] \mid 0 \leq k < m \} $ - Let $ c_j $ be the multiset of letters in column $ j $: $ c_j = \{ G[k][j] \mid 0 \leq k < n \} $ A letter at position $ (i, j) $ is **crossed out** if and only if: $ \text{count}_{r_i}(G[i][j]) > 1 $ or $ \text{count}_{c_j}(G[i][j]) > 1 $ Let $ R \subseteq \{0, \dots, n-1\} \times \{0, \dots, m-1\} $ be the set of **remaining** (uncrossed) cells: $ R = \{ (i, j) \mid \text{count}_{r_i}(G[i][j]) = 1 \text{ and } \text{count}_{c_j}(G[i][j]) = 1 \} $ The encrypted word is formed by reading the letters in $ R $ in **row-major order**: For $ i = 0 $ to $ n-1 $, and for each $ i $, for $ j = 0 $ to $ m-1 $, include $ G[i][j] $ in the output if $ (i, j) \in R $. Output the concatenation of all such $ G[i][j] $ for $ (i, j) \in R $, in row-major order.
Samples
Input #1
3 3
cba
bcd
cbc
Output #1
abcd
Input #2
5 5
fcofd
ooedo
afaoa
rdcdf
eofsf
Output #2
codeforces
API Response (JSON)
{
  "problem": {
    "name": "B. African Crossword",
    "description": {
      "content": "An African crossword is a rectangular table _n_ × _m_ in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs t",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF90B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "An African crossword is a rectangular table _n_ × _m_ in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs t...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "非洲填字游戏是一个大小为 $n × m$ 的矩形表格。表格中的每个单元格恰好包含一个字母。该表格(也称为网格)包含一个需要解密的加密单词。\n\n要解谜该填字游戏,你需要划掉所有在行和列中重复出现的字母。换句话说,一个字母只有在对应的行或列中至少还有一个与之完全相同的字母时,才被划掉。此外,所有这样的字母将同时被划掉。\n\n当所有重复的字母都被划掉后,我们将剩余的字母按顺序写成一个字符串。位置较高的字母...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ G $ be an $ n \\times m $ matrix over the alphabet $ \\Sigma $ (lowercase Latin letters), where $ G[i][j] $ denotes the letter at row $ i $, column $ j $.\n\nDefine:\n- For each cell $ (i, j) $, let ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments