F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

WORM

Time Limit: 20000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 365    Accepted Submission(s): 198


Problem Description
Partychen discover a strange worm in ECNU.The worm is too laze so it spends most of his life in sleep,the only way to wake it up is turn the worm's body into the same color. This worm¡¯s body consist of N body sections, each body section could only be three kinds of colors: red (r), green (g), blue (b) . This worm's body color could change with the following two rules:
1:two adjacent section with different colors can change into another at the same time, such as rg could be bb,bg could be rr etc.
2: only one change could happen in the worm¡¯s body per second.
Illustration below shows a series change in two seconds:

Now Partychen want you to tell him how long it required to wake up the strange worm at least.
 

Input
The first line of input contains one integer N( N<=200),specifying the number of test cases to follow.The following N lines each line contain a series characters denotes the color status of the worm¡¯s body.¡¯r¡¯,¡¯g¡¯,¡¯b¡¯ represents ¡°red¡±,¡±¡®green¡±,¡±blue¡± respectively.there are no extra spaces or blanks in the characters and the total length of each line is at most 10.
 

Output
Output one line each case.if there is no way to wake up the strange worm output ¡°No solution!¡±,otherwise output the smallest total time to do so.
 

Sample Input
8 rbgrg rbbgbbr bgr bgrbrgbr bggrgbgrr gbrggrbggr rrrrr bgbr
 

Sample Output
5 7 1 6 No solution! 8 0 4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-25 14:34:22, Gzip enabled