University of Waterloo Logo and CEMC Banner

2023 Canadian Computing Competition
Junior Problems

Problem J1: Deliv-e-droid

Problem Description

In the game, Deliv-e-droid, a robot droid has to deliver packages while avoiding obstacles. At the end of the game, the final score is calculated based on the following point system:

Your job is to determine the final score at the end of a game.

Input Specification

The input will consist of two lines. The first line will contain a non-negative integer \(P\), representing the number of packages delivered. The second line will contain a non-negative integer \(C\), representing the number of collisions with obstacles.

Output Specification

The output will consist of a single integer \(F\), representing the final score.

Sample Input 1

5
2

Output for Sample Input 1

730

Explanation of Output for Sample Input 1

There are 5 packages delivered, so \(5 \times 50=250\) points are gained. There are 2 collisions, so \(2 \times 10=20\) points are lost. Since \(5>2\), a bonus 500 points are earned. Therefore, the final score is \(250 - 20 + 500 =730\).

Sample Input 2

0
10

Output for Sample Input 2

-100

Explanation of Output for Sample Input 2

There are 0 packages delivered, so \(0 \times 50=0\) points are gained. There are 10 collisions, so \(10 \times 10=100\) points are lost. Since \(0 \leq 10\), no bonus points are earned. Therefore, the final score is \(0 - 100 + 0 = -100\).

Problem J2: Chili Peppers

Problem Description

Ron is cooking chili using an assortment of peppers.

The spiciness of a pepper is measured in Scolville Heat Units (SHU). Ron’s chili is currently not spicy at all, but each time Ron adds a pepper, the total spiciness of the chili increases by the SHU value of that pepper.

The SHU values of the peppers available to Ron are shown in the following table:

Pepper Name Scolville Heat Units
Poblano 1500
Mirasol 6000
Serrano 15500
Cayenne 40000
Thai 75000
Habanero 125000

Your job is to determine the total spiciness of Ron’s chili after he has finished adding peppers.

Input Specification

The first line of input will contain a positive integer \(N\), representing the number of peppers Ron adds to his chili. The next \(N\) lines will each contain the name of a pepper Ron has added. Each pepper name will exactly match a name that appears in the table above. Note that more than one pepper of the same name can be added.

Output Specification

The output will consist of a positive integer \(T\), representing the total spiciness of Ron’s chili.

Sample Input

4 
Poblano 
Cayenne 
Thai 
Poblano

Output for Sample Input

118000

Explanation of Output for Sample Input

A Poblano pepper has an SHU value of \(1500\). A Cayenne pepper has an SHU value of \(40000\). A Thai pepper has an SHU value of \(75000\). The total spiciness of Ron’s chili is therefore \(1500 + 40000 + 75000 + 1500 = 118000\).

Problem J3: Special Event

Problem Description

You are trying to schedule a special event on one of five possible days.

Your job is to determine on which day you should schedule the event, so that the largest number of interested people are able to attend.

Input Specification

The first line of input will contain a positive integer \(N\), representing the number of people interested in attending your event. The next \(N\) lines will each contain one person’s availability using one character for each of Day 1, Day 2, Day 3, Day 4, and Day 5 (in that order). The character Y means the person is able to attend and a period (.) means the person is not able to attend.

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

Marks Description
6 There will be exactly one day on which every person will be able to attend.
6 There will be exactly one day on which the largest number of people will be able to attend.
3 There might be more than one day on which the largest number of people will be able to attend.

Output Specification

The output will consist of one line listing the day number(s) on which the largest number of interested people are able to attend.

If there is more than one day on which the largest number of people are able to attend, output all of these day numbers in increasing order and separated by commas (without spaces).

Sample Input 1

3
YY.Y.
...Y.
.YYY.

Output for Sample Input 1

4

Explanation of Output for Sample Input 1

All three people are able to attend on Day 4, and they are not all available on any other day.

Sample Input 2

5
YY..Y
.YY.Y
.Y.Y.
.YY.Y
Y...Y

Output for Sample Input 2

2,5

Explanation of Output for Sample Input 2

There is no day on which all five people are able to attend. Four people are able to attend on both Day 2 and Day 5.

Problem J4/S1: Trianglane

Problem Description

Bocchi the Builder just finished constructing her latest project: a laneway consisting of two rows of white equilateral triangular tiles. However, at the last moment, disaster struck! She accidentally spilled black paint on some of the tiles. Now, some of the tiles are wet and the other tiles are dry. Bocchi must place warning tape around the perimeters of all wet areas. Can you help her determine how many metres of tape she needs?

The first triangular tile will point upwards. Each pair of adjacent tiles (that is, tiles that share a common side) will point in opposite directions. Each tile has a side length of 1 metre.

Input Specification

The first line of input will consist of one positive integer \(C\), representing the number of columns.

The next two lines will each consist of \(C\) integers separated by spaces. Each integer represents the colour of a tile along the laneway, with 1 indicating that the tile is black (wet) and 0 indicating that the tile is white (dry).

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

Marks Description Bound
3 The laneway is not very long, black tiles are never adjacent and the second row is fully white. \(C \le 2\,000\)
3 The laneway is not very long, black tiles may be adjacent and the second row is fully white. \(C \le 2\,000\)
5 The laneway is not very long, black tiles may be adjacent and may appear in the second row. \(C \le 2\,000\)
4 The laneway may be very long, black tiles may be adjacent and may appear in the second row. \(C \le 200\,000\)

Output Specification

Output a single integer representing the length of tape Bocchi needs, in metres.

Sample Input 1

5
1 0 1 0 1
0 0 0 0 0 

Output for Sample Input 1

9

Explanation of Output for Sample Input 1

The tiles are painted as follows, creating three wet areas. Bocchi will need 9 metres of warning tape as shown in yellow.

Two rows of five equilateral triangle tiles. In the top row, the tiles are pointing up, down, up, down, up. In the bottom row, the tiles are pointing down, up, down, up, down. Each tile pointing upward in the top row shares a side with a tile pointing downward in the bottom row. Each tile pointing upward in the top row is outlined in yellow.

Sample Input 2

7
0 0 1 1 0 1 0
0 0 1 0 1 0 0

Output for Sample Input 2

11

Explanation of Output for Sample Input 2

The tiles are painted as follows, creating three wet areas. Bocchi will need 5 metres of warning tape to surround one area and 3 metres of warning tape to surround each of the other two areas as shown in yellow.

Two rows of seven tiles arranged as in the previous input. The third and fourth tiles in the top row (pointing up then down) and the third tile in the bottom row (pointing down) form a trapezoidal area outlined in yellow. Also, the sixth tile in the top row and the fifth tile in the bottom row are each outlined in yellow.

Problem J5: CCC Word Hunt

Problem Description

In the CCC Word Hunt, words are hidden in a grid of letters. The letters of a hidden word always appear in order on horizontal, vertical, or diagonal line segments in one of two ways. One way is for the letters of a word to appear on one line segment. The other way is for the letters of a word to appear on one line segment up to some letter and then on a second line segment that forms a right angle at this letter.

Given a grid of letters and a single word to search for, your job is to determine the number of times that particular word is hidden in the grid.

Input Specification

The first line of input will contain a string of distinct uppercase letters, \(W\), representing the word you are to search for in the grid. The length of \(W\) will be at least two. The second line of input will be an integer \(R~(1 \le R \le 100)\), where \(R\) is the number of rows in the grid. The third line of input will be an integer \(C~(1 \le C \le 100)\), where \(C\) is the number of columns in the grid.

The remaining input will provide the letters in the grid. It will consist of \(R\) lines, where each line contains \(C\) uppercase letters separated by single spaces.

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

Marks Word Placement
2 On one horizontal line segment
2 On one horizontal or vertical line segment
2 On one horizontal, vertical, or diagonal line segment
9 On one line segment or two perpendicular line segments

Output Specification

The output will consist of a single non-negative integer \(H\), representing the number of times the word is hidden in the grid.

Sample Input 1

MENU
5
7
F T R U B L K
P M N A X C U
A E R C N E O
M N E U A R M
M U N E M N S

Output for Sample Input 1

3

Explanation of Output for Sample Input 1

The word MENU is hidden three times in the grid. Once horizontally, once vertically, and once diagonally as shown. Notice that a single letter can be used more than once.

Menu appears vertically in the second column of the grid of letters, starting in the second row of letters and moving downwards. It also appears horizontally and backwards in the fifth row, starting at the fifth square and moving to the left. It also appears diagonally, starting at the first square in the fourth row and moving up and to the right.

Sample Input 2

NATURE
6
9
N A T S F E G Q N
S A I B M R H F A
C F T J C U C L T
K B H U P T A N U
D P R R R J D I R
I E E K M E G B E

Output for Sample Input 2

4

Explanation of Output for Sample Input 2

The word NATURE is hidden four times in the grid. Once diagonally, once vertically, and twice on perpendicular line segments.

Nature appears diagonally, starting at the top-left letter of the grid and moving down and to the right, and appears vertically in the rightmost column, starting at the top and moving down. It appears as a capital L shape starting in the fourth row and eighth column and moving two to the left, then up three. It appears as a backwards and rotated L shape starting at the top-left letter and moving three diagonally down to the right, then moving two diagonally down to the left.