B. Flag of Berland
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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).

Examples
input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
output
YES
input
4 3
BRG
BRG
BRG
BRG
output
YES
input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
output
NO
input
4 4
RRRR
RRRR
BBBB
GGGG
output
NO
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.

这题还是不错的,题意是如果 可以分割成3条,R G B各一条,那就输出YES,每条可以包含多行,但是每条的行数必须相等

打了一大堆补丁,最后过了

n,m = map(int,raw_input().split())
mark = 1
s = []
for i in range(n):
tmp = raw_input();
s.append(tmp);
for c in range(m):
if c + 1 < m and tmp[c] != tmp[c + 1]:
mark = 0;
r = 0
g = 0
b = 0
for a in s:
for c in a:
if c =='R':
r = r + 1
if c == 'G':
g = g + 1
if c == 'B':
b = b + 1
if mark == 1:
num = 1
w = []
for i in range(n):
if i + 1 < n and s[i][0] == s[i + 1][0]:
num = num + 1;
else:
w.append(int(num))
num = 1;
for i in range(len(w)):
if i + 1 < len(w) and w[i] != w[i + 1]:
mark = 2;
if mark == 1 and len(w) == 3 and r == g and g == b:
print "YES"
else:
print "NO"
else :
for y in range(m):
for x in range(n):
if x + 1 < n and s[x][y] != s[x + 1][y]:
mark = 2;
break;
if mark == 2:
print "NO"
else :
num = 1
w = []
for i in range(m):
if i + 1 < m and s[0][i] == s[0][i + 1]:
num = num + 1
else:
w.append(int(num));
num = 1;
for i in range(len(w)):
if i + 1 < len(w) and w[i] != w[i + 1]:
mark = 2;
if mark == 0 and len(w) == 3 and r == g and g ==b:
print "YES"
else:
print "NO"

B. Flag of Berland的更多相关文章

  1. Codefroces Educational Round 26 837 B. Flag of Berland

    B. Flag of Berland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. AC日记——Flag Codeforces 16a

    A. Flag time limit per test 2 seconds memory limit per test 64 megabytes input standard input output ...

  3. CF16A Flag

    CF16A Flag 题意翻译 题目描述 根据一项新的ISO标准,每一个国家的国旗应该是一个n×m的格子场,其中每个格子最多有10种不同的颜色.并且国旗应该有条纹:旗帜的每一行应包含相同颜色的方块,相 ...

  4. Educational Codeforces Round 26 B,C

    B. Flag of Berland 链接:http://codeforces.com/contest/837/problem/B 思路:题目要求判断三个字母是否是条纹型的,而且宽和高相同,那么先求出 ...

  5. Educational Codeforces Round 26 A B C题

    题目链接 A. Text Volume 题意:计算句子中,每个单词大写字母出现次数最多的那个的出现次数(混不混乱QAQ). 解题思路:注意getchar()就没啥了. #include<cstd ...

  6. Codeforces Round #207 (Div. 2)A B C E 水 思路 set 恶心分类

    A. Group of Students time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Educational Codeforces Round 26

    Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...

  8. Codeforces Round #375 (Div. 2) D. Lakes in Berland dfs

    D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. B. Berland Bingo

    Lately, a national version of a bingo game has become very popular in Berland. There are n players p ...

随机推荐

  1. POJ 1201 Intervals(差分约束 区间约束模版)

    关于差分约束详情可阅读:http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html 题意: 给定n个区间[L,R], 每个区间至 ...

  2. 洛谷 P1938 [USACO09NOV] 找工就业Job Hunt

    这道题可以说是一个复活SPFA的题 因为数据比较小,SPFA也比较简单 那就复习(复读)一次SPFA吧 #include<iostream> #include<cstdio> ...

  3. luogu1494 [国家集训队]小Z的袜子

    #include <algorithm> #include <iostream> #include <cstdio> #include <cmath> ...

  4. 详解Python装饰器由浅入深

    装饰器的功能在很多语言中都有,名字也不尽相同,其实它体现的是一种设计模式,强调的是开放封闭原则,更多的用于后期功能升级而不是编写新的代码.装饰器不光能装饰函数,也能装饰其他的对象,比如类,但通常,我们 ...

  5. Leetcode 304.二维区域和检索-矩阵不可变

    二维区域和检索 - 矩阵不可变 给定一个二维矩阵,计算其子矩形范围内元素的总和,该子矩阵的左上角为 (row1, col1) ,右下角为 (row2, col2). 上图子矩阵左上角 (row1, c ...

  6. [USACO11NOV]牛的障碍Cow Steeplechase(匈牙利算法)

    洛谷传送门 题目描述: 给出N平行于坐标轴的线段,要你选出尽量多的线段使得这些线段两两没有交点(顶点也算),横的与横的,竖的与竖的线段之间保证没有交点,输出最多能选出多少条线段. 因为横的与横的,竖的 ...

  7. PHP应用日期与时间

    <?php/* 时间戳 * * 1. 是一个整数 * 2. 1970-1-1 到现在的秒数 1213212121 * * 2014-02-14 11:11:11 * * 02/14/2014 1 ...

  8. SpringBoot Beans定义 连接池

    SpringBoot Beans定义 原有Spring框架,定义Bean方法如下 xml配置 组件扫描.@Controller.@Service... 原有Spring框架,参数注入方法如下 常用的参 ...

  9. 背包!背包!HDU 2602 Bone Collector + HDU 1114 Piggy-Bank + HDU 2191 512

    http://acm.hdu.edu.cn/showproblem.php?pid=2602 第一题 01背包问题 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  10. 【BZOJ1031】字符加密Cipher(后缀数组)

    题意:将一个长度为2n(复制粘贴后)的字符串的所有长度为n的后缀从小到大排序,并依次输出它们的最后一个字母. n<=100000 思路:裸SA,模板真难背 P党不得不写成C++风格 ..]of ...