PenguinPals
SRM 566 · 2012-12-13 · by tehqin
Problem Statement
Penguin Pals is a match making service that matches penguins to new friends, using the following procedure:
- Each penguin is asked a single question: "Do you prefer the color blue, or the color red?"
- All penguins are arranged so that they stand on a circle, equally spaced.
- The organizers draw some straight lines, connecting some pairs of penguins. Each penguin may only be connected to at most one other penguin. Two penguins cannot be connected if they prefer a different color.
- Each penguin who is connected to some other penguin follows the line to find their match.
The only problem with the above system was that it allowed penguins to collide if two lines crossed each other. Therefore, a new additional rule was adopted: no two lines may cross. Penguin Pals now has some penguins arranged on a circle (after step 2 of the above procedure). They need to know the maximum number of pairs of penguins they can create.
You are given a
Constraints
- colors will contain between 1 and 50 characters, inclusive.
- Each character of colors will be either 'R' or 'B'.
"RRBRBRBB" Returns: 3
In this picture the penguins have been colored in their preferred color.
"RRRR" Returns: 2
"BBBBB" Returns: 2
"RBRBRBRBR" Returns: 4
"RRRBRBRBRBRB" Returns: 5
Submissions are judged against all 129 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PenguinPals with a public method int findMaximumMatching(string colors) · 129 test cases · 2 s / 256 MB per case