CCC '26 J3 - Creative Candy Consumption

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 3.0s
Memory limit: 1G

Problem type
Canadian Computing Competition: 2026 Stage 1, Junior #3

Ngoc and Minh devised a creative way to eat candy that comes in three different colours: red, green, and blue.

They begin by arranging some coloured candies into a line. Then, the candy at the front of Ngoc's line is compared to the candy at the front of Minh's line. If both candies are the same colour, then Ngoc and Minh each eat the candy at the front of their own line. If the candies are different colours, then the person with the winning candy eats the losing candy, and the winning candy stays at the front of its line.

  • Red candy R wins against green candy G
  • Green candy G wins against blue candy B
  • Blue candy B wins against red candy R

This process of comparing and eating candy repeats until there is at least one empty line of candy. When that happens, if one person still has candy left in their line, then that person eats all of their leftover candy.

Your job is to determine how much candy each person eats.

Input Specification

The first line of input contains a sequence of N letters, representing Ngoc's line of candy. The second line of input contains a sequence of M letters, representing Minh's line of candy. Each letter will be an uppercase R, G, or B representing the colours red, green, and blue, respectively. The first letter in each sequence represents the colour of the candy at the front of that person's line. (There will always be at least one letter in each sequence.)

The following table shows how the 15 available marks are distributed:

Marks Description Bounds
2 Ngoc and Minh each have one candy. N = 1 and M = 1
4 Either Ngoc's line will empty first, or both lines will
empty at the same time. Ngoc and Minh could have
many candies.
N \le 50 and M \le 50
7 Ngoc and Minh could have many candies N \le 50 and M \le 50
2 Ngoc and Minh could have an absurd amount of candy. N \le 1\ 000\ 000 and M \le 1\ 000\ 000

Output Specification

There will be two lines of output.

On the first line, output the number of candies Ngoc eats. On the second line, output the number of candies Minh eats.

Sample Input

RRR
RGBB

Sample Output

2
5

Explanation for Sample Output

Candy Lines Description
Ngoc: RRR
Minh: RGBB
Both people have red candy at the front of their lines.
Ngoc eats her red candy and Minh eats his red candy
So far, Ngoc has eaten 1 candy and Minh has eaten 1 candy.
Ngoc: RR
Minh: GBB
Ngoc's red candy wins against Minh's green candy.
Ngoc eats Minh's green candy.
So far, Ngoc has eaten 2 candies and Minh has eaten 1 candy.
Ngoc: RR
Minh: BB
Minh's blue candy wins against Ngoc's red candy.
Minh eats Ngoc's red candy.
So far, Ngoc has eaten 2 candies and Minh has eaten 2 candies.
Ngoc: R
Minh: BB
Minh's blue candy wins against Ngoc's red candy.
Minh eats Ngoc's red candy.
So far, Ngoc has eaten 2 candies and Minh has eaten 3 candies.
Ngoc:
Minh: BB
Ngoc's line of candy is empty, so the process ends.
Minh eats his remaining blue candies.
In total, Ngoc eats 2 candies and Minh eats 5 candies.

Comments


  • 0
    Smore_Math2014  commented on March 2, 2026, 10:05 p.m.

    SUGAR RUSH!!!


    • 0
      R_G  commented on March 2, 2026, 11:30 p.m.

      1 million candies is quite a lot!