CF6B.President's Office

普及-

通过率:0%

时间限制:2.00s

内存限制:64MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.

The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.

伯兰德总统拥有一间非常宽敞的办公室,除了他本人之外,还有他的下属在此办公。每位下属以及总统本人,都拥有一张颜色独一无二的办公桌。每张办公桌均为矩形,且其各边均与办公室墙壁平行。某日,总统决定召开一次会议,所有他的副手都将参会。不幸的是,他不记得自己究竟有多少位副手,但他记得:每位副手的办公桌都与他自己的办公桌相邻,即总统的办公桌与每位副手的办公桌之间存在一段长度为正的公共边。

办公室平面图可视为一个具有 nn 行 mm 列的矩阵。该矩阵中的每个单元格要么为空,要么属于某张办公桌的一部分。每张办公桌以一个大写拉丁字母表示其颜色;字符「点」(「.」)表示空单元格。

输入格式

The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.

第一行包含两个由空格分隔的整数 nn、mm(1 ≤ n, m ≤ 1001 ≤ n, m ≤ 100)——分别表示办公室房间的长度和宽度,以及一个字符 cc —— 总统办公桌的颜色。接下来的 nn 行,每行包含 mm 个字符,描述该办公室房间。保证每张办公桌的颜色均唯一,且每张办公桌在给定矩阵中对应一个连续的子矩形。所有颜色均用大写拉丁字母标记。

输出格式

Print the only number — the amount of President's deputies.

输出唯一的数字——总统副手的数量。

输入输出样例

  • 输入#1

    3 4 R
    G.B.
    .RR.
    TTT.

    输出#1

    2
  • 输入#2

    3 3 Z
    ...
    .H.
    ..Z

    输出#2

    0

输入解题思路,AI测评打分。不知道怎么写?

首页