8389: Cow Art

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:23 通过:15

题目描述

A little known fact about cows is the fact that they are red-green colorblind, meaning that red and green look identical to them. This makes it especially difficult to design artwork that is appealing to cows as well as humans.


 Consider a square painting that is described by an N x N grid of characters (1 <= N <= 100), each one either R (red), G (green), or B (blue). A painting is interesting if it has many colored "regions" that can be distinguished from each-other. Two characters belong to the same region if they are directly adjacent (east, west, north, or south), and if they are indistinguishable in color. For example, the painting 


RRRBB 
GGBBB 
BBBRR 
BBRRR 
RRRRR 


has 4 regions (2 red, 1 blue, and 1 green) if viewed by a human, but only 3 regions (2 red-green, 1 blue) if viewed by a cow. Given a painting as input, please help compute the number of regions in the painting when viewed by a human and by a cow.


关于奶牛的一个鲜为人知的事实是,它们是红绿色色盲,这意味着红和绿看起来与它们完全相同。这使得设计既能吸引牛也能吸引人的艺术品特别困难。考虑一幅正方形绘画,由N x N个字符组成的网格(1<=N<=100)描述,每个字符要么是R(红色),要么是G(绿色),要么是B(蓝色)。如果一幅画有许多可以相互区分的彩色“区域”,那么它就是有趣的。如果两个字符直接相邻(东、西、北或南),并且颜色不可区分,则它们属于同一区域。例如,如果由人类观看,绘画RRRBB GGBBB BBBRR BBRRR RRRRR有4个区域(2个红色、1个蓝色和1个绿色),但如果由奶牛观看,则只有3个区域(2个红色、1个蓝色)。给定一幅画作为输入,请帮助计算人类和奶牛观看时画中的区域数。

输入格式

* Line 1: The integer N. * Lines 2..1+N: Each line contains a string with N characters, describing one row of a painting.

输出格式

* Line 1: Two space-separated integers, telling the number of regions in the painting when viewed by a human and by a cow.

输入样例 复制

5
RRRBB
GGBBB
BBBRR
BBRRR
RRRRR

输出样例 复制

4 3