codeforces-scrape

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

1191B.md (2713B)


      1 Source: https://codeforces.com/problemset/problem/1191/B
      2 
      3 B. Tokitsukaze and Mahjong
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $1$ to $9$). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, $\ldots$, 9m, 1p, 2p, $\ldots$, 9p, 1s, 2s, $\ldots$, 9s.
     22 
     23 In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
     24 
     25 Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
     26 
     27 Here are some useful definitions in this game:
     28 
     29 * A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
     30 * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
     31 * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
     32 
     33 Some examples:
     34 
     35 * [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu;
     36 * [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
     37 * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
     38 
     39 Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
     40 
     41 Input
     42 
     43 The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from $1$ to $9$ and the second character is m, p or s.
     44 
     45 Output
     46 
     47 Print a single integer — the minimum number of extra suited tiles she needs to draw.
     48 
     49 Examples
     50 
     51 Input
     52 
     53 ```
     54 1s 2s 3s
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 0
     61 ```
     62 
     63 Input
     64 
     65 ```
     66 9m 9m 9m
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 0
     73 ```
     74 
     75 Input
     76 
     77 ```
     78 3p 9m 2p
     79 ```
     80 
     81 Output
     82 
     83 ```
     84 1
     85 ```
     86 
     87 Note
     88 
     89 In the first example, Tokitsukaze already has a shuntsu.
     90 
     91 In the second example, Tokitsukaze already has a koutsu.
     92 
     93 In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].