B. Flag of Berland

Codeforces
IDCF837B
Time1000ms
Memory256MB
Difficulty
brute forceimplementation
English · Original
Chinese · Translation
Formal · Original
The flag of Berland is such rectangular field _n_ × _m_ that satisfies following conditions: * Flag consists of three colors which correspond to letters _'R'_, _'G'_ and _'B'_. * Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has **exactly one color**. * Each color should be used in **exactly one stripe**. You are given a field _n_ × _m_, consisting of characters _'R'_, _'G'_ and _'B'_. Output "_YES_" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "_NO_" (without quotes). ## Input The first line contains two integer numbers _n_ and _m_ (1 ≤ _n_, _m_ ≤ 100) — the sizes of the field. Each of the following _n_ lines consisting of _m_ characters _'R'_, _'G'_ and _'B'_ — the description of the field. ## Output Print "_YES_" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "_NO_" (without quotes). [samples] ## Note The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — _2_, _1_ and _1_.
贝兰的国旗是一个满足以下条件的矩形区域 #cf_span[n × m]: 给你一个由字符 _'R'_、_'G'_ 和 _'B'_ 组成的 #cf_span[n × m] 区域。如果该区域对应贝兰的正确国旗,则输出 "_YES_"(不含引号);否则,输出 "_NO_"(不含引号)。 第一行包含两个整数 #cf_span[n] 和 #cf_span[m](#cf_span[1 ≤ n, m ≤ 100])——表示区域的尺寸。 接下来的 #cf_span[n] 行,每行包含 #cf_span[m] 个字符 _'R'_、_'G'_ 和 _'B'_——表示区域的描述。 如果给定区域对应贝兰的正确国旗,则输出 "_YES_"(不含引号);否则,输出 "_NO_"(不含引号)。 第三个示例中的区域没有三条平行的条纹。 第四个示例中的区域行彼此平行且与边界平行,但它们的高度不同——为 _2_、_1_ 和 _1_。 ## Input 第一行包含两个整数 #cf_span[n] 和 #cf_span[m](#cf_span[1 ≤ n, m ≤ 100])——表示区域的尺寸。接下来的 #cf_span[n] 行,每行包含 #cf_span[m] 个字符 _'R'_、_'G'_ 和 _'B'_——表示区域的描述。 ## Output 如果给定区域对应贝兰的正确国旗,则输出 "_YES_"(不含引号);否则,输出 "_NO_"(不含引号)。 [samples] ## Note 第三个示例中的区域没有三条平行的条纹。第四个示例中的区域行彼此平行且与边界平行,但它们的高度不同——为 _2_、_1_ 和 _1_。
**Definitions** Let $ n, m \in \mathbb{Z} $ denote the dimensions of the field, with $ 1 \leq n, m \leq 100 $. Let $ F \in \{R, G, B\}^{n \times m} $ be the grid representing the flag, where $ F[i][j] $ is the color at row $ i $, column $ j $. **Constraints** 1. Each cell $ F[i][j] \in \{R, G, B\} $. 2. The flag must consist of exactly three **horizontal** stripes (i.e., full-width rows), each of uniform color. 3. The three stripes must be **parallel to the horizontal borders** (i.e., each stripe spans all $ m $ columns). 4. The three stripes must have **distinct colors** from $ \{R, G, B\} $, each appearing exactly once. 5. The heights of the stripes (number of consecutive rows per stripe) must be **positive integers** summing to $ n $, and **no stripe may be split** across non-consecutive row blocks. **Objective** Determine whether $ F $ satisfies all above constraints. Output: $$ \begin{cases} \text{"YES"} & \text{if } F \text{ is a valid Berland flag} \\ \text{"NO"} & \text{otherwise} \end{cases} $$
Samples
Input #1
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output #1
YES
Input #2
4 3
BRG
BRG
BRG
BRG
Output #2
YES
Input #3
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output #3
NO
Input #4
4 4
RRRR
RRRR
BBBB
GGGG
Output #4
NO
API Response (JSON)
{
  "problem": {
    "name": "B. Flag of Berland",
    "description": {
      "content": "The flag of Berland is such rectangular field _n_ × _m_ that satisfies following conditions: *   Flag consists of three colors which correspond to letters _'R'_, _'G'_ and _'B'_. *   Flag consists of",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF837B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The flag of Berland is such rectangular field _n_ × _m_ that satisfies following conditions:\n\n*   Flag consists of three colors which correspond to letters _'R'_, _'G'_ and _'B'_.\n*   Flag consists of...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "贝兰的国旗是一个满足以下条件的矩形区域 #cf_span[n × m]:\n\n给你一个由字符 _'R'_、_'G'_ 和 _'B'_ 组成的 #cf_span[n × m] 区域。如果该区域对应贝兰的正确国旗,则输出 \"_YES_\"(不含引号);否则,输出 \"_NO_\"(不含引号)。\n\n第一行包含两个整数 #cf_span[n] 和 #cf_span[m](#cf_span[1 ≤ n, m ≤ 1...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z} $ denote the dimensions of the field, with $ 1 \\leq n, m \\leq 100 $.  \nLet $ F \\in \\{R, G, B\\}^{n \\times m} $ be the grid representing the flag, where $ F[i...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments