Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Paint Me Less
Description Alice likes drawing very much. But, maybe, precisely speaking, she just loves painting a sheet of paper into a single color. Today she gets a paper with some colors on it and she starts to paint it all black. The rectangular paper is divided into several rows and columns. Each block, with a single color, is connected to four other blocks which are the blocks directly upper, lower, left or right to it. All the blocks with the same color and connected to each other forms a region. Every time Alice paints, she chooses one region and paint all blocks of that region with a same color, which counted as a step. Unfortunately, Alice is not good at math. And she always paints a lot of times which makes her tired and unhappy. Could you help her painting in an easy way? Input The input file contains multiple cases until the end of file. The first line of each case consists of two integers, Colors are represented by integers in the range [0, 19]. And the target color, which Alice wants to paint the whole paper into, is zero. Output For each test case, print an integer S, the minimal steps Alice must paint, on the first line. Then describe your solution in the following S lines in this format: Sample Input 2 2 3 1 1 1 Sample Output 2 1 2 3 2 2 0 Source |

[Submit] [Go Back] [Status] [Discuss]

Any problem, Please Contact Administrator