codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

6B.md (1728B)


      1 Source: https://codeforces.com/problemset/problem/6/B
      2 
      3 B. President's Office
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 64 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 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.
     24 
     25 Input
     26 
     27 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.
     28 
     29 Output
     30 
     31 Print the only number — the amount of President's deputies.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 3 4 R  
     39 G.B.  
     40 .RR.  
     41 TTT.
     42 ```
     43 
     44 Output
     45 
     46 ```
     47 2
     48 ```
     49 
     50 Input
     51 
     52 ```
     53 3 3 Z  
     54 ...  
     55 .H.  
     56 ..Z
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 0
     63 ```