10
Australian Informatics Olympiad Thursday 4 September, 2014 Senior Paper Duration: 3 hours 3 questions All questions should be attempted

AIO Senior 2014

Embed Size (px)

DESCRIPTION

Australian Competition Paper

Citation preview

Page 1: AIO Senior 2014

Australian Informatics Olympiad

Thursday 4 September, 2014

Senior Paper

Duration: 3 hours

3 questions

All questions should be attempted

Page 2: AIO Senior 2014

Australian Informatics Olympiad 2014 (Senior) — Important Notes 1

Important Notes

Some final reminders for competitors:

• Solutions may be submitted in C, C++, C#, Pascal, Java, PHP or Python.

• Solution templates can be downloaded from the submission website. These templates performall the necessary file input and output for each question. We strongly recommend using theseas a starting point for your solutions.

• You should submit your solutions directly via the internet during the three hours of thecontest. Please read the Contest Rules in the Information Booklet if you have not yet doneso.

• Some languages have special constraints:

– Pascal programmers may not import any units except for Math, Strings and/or SysUtils.

– Java programmers may not use any classes aside from those in packages java.lang,java.io and java.util. Solutions must be contained in a single class called Solution,and must be run from the routine

public static void main(String[] args)

within this Solution class.

– PHP programmers may not use any functions provided by extensions or external li-braries.

– Python programmers may not import any packages except for sys.

• If you are not sure about how your program should be structured, see the submission sitehttp://orac.amt.edu.au/aio/ for sample solutions to past problems in each of the sup-ported languages (you are welcome to browse these during the contest).

It is particularly recommended that Java and PHP programmers visit this site, due to theunusual constraints described above.

• Don’t leave all your submissions until the last few minutes! Submitting your solu-tions may take a little time, and once your three hours are over the submission site will notaccept any more solutions.

The best strategy is to submit solutions as you write them. If you improve a solution laterin the contest, you can always resubmit it.

• If you have any queries, please ask your teacher to email [email protected] and we willrespond as soon as possible. For urgent issues (such as losing your internet connection),please ask your teacher to contact either Mr Jarrah Lacko on 02 8091 2321 or Mr RobertNewey on 0432 748 904.

Please see the full contest rules for further information.

Good luck!

Page 3: AIO Senior 2014

Australian Informatics Olympiad 2014 (Senior) — Why Did I Score Zero? 2

Why Did I Score Zero?

Candidates sometimes score zero even though they believe that they have a working solution to aproblem. Below are some of the common reasons that good solutions score zero.Note that examples of solutions that score 100% in the various AIO languages can be found onthe website http://orac.amt.edu.au/aio/.

Incorrect Input and Output Files

Each problem statement lists the names of its input and output files, similar to the example below.

Input File: zeroin.txt

Output File: zeroout.txt

In this example, if you try to open any of

• "a:\zeroin.txt"

• "c:\mydir\zeroin.txt"

• "input.txt"

then the file you are looking for will almost certainly not be on the judging machine and yourprogram will score zero. Just open "zeroin.txt" without any additional directory information.The same goes for the output file.

Keyboard and Mouse Input

Your program should not be interactive. It should not have a graphical user interface. It shouldsimply read from the input file, write to the output file, and exit. If your program requires anyinput from the user, the judging software will not supply this input and you will exceed the timelimit. Examples include:

• ’Please enter the following value...’

• ’Press any key to exit...’

• Providing a form on which the user has to click a button to start the program.

Incorrect Output Format

Each problem is very precise about how the output file should be formatted. Your score is assignedby a judging program which tries to automatically extract your solution from your output file.Every problem statement includes sample input and output files, as a way of illustrating theseformats. For Problem 1 on the Senior paper, the first sample output file contains the single line:

4

In this example, the following output files would almost certainly score zero:

• The answer is 4.

• "4"

Violating Contest Rules

Each year a few programs are submitted that violate the contest rules. Be sure to read the ProgramRestrictions section of the rules, which details specific restrictions for each programming language.If you are unsure about anything then please email [email protected] for clarification.

Page 4: AIO Senior 2014

Australian Informatics Olympiad 2014 (Senior) — Giant Hippos 3

Problem 1

Giant Hippos

Input File: hippoin.txt

Output File: hippoout.txt

Time Limit: 1 second

Your backyard has been overrun by preposterously large hippos, and they are eating the tulips!

You have a line of N tulips, labelled from 1 to N . There are H hippos standing next to differenttulips . . . and they are already eating them! If you don’t act fast, they will eat all the tulips inyour garden.

You have enough plywood to build up to F fences. Each fence will be built between two tulipsthat are next to each other. Hippos cannot go through fences (or over them, or under them, oraround them).

Once you have built your fences, the hippos will roam back and forth along the line of tulips,eating all the tulips they can reach without crossing your fences. What is the greatest number oftulips you can save?

Input

Your program should read from the file hippoin.txt.

• The first line of input will contain three space-separated integers N , H and F : the numberof tulips, hippos, and fences you can build respectively.

• The next H lines will each contain an integer describing which tulip one hippo is eating.These will be in increasing order. No two hippos start at the same tulip.

Output

Your program should write to the file hippoout.txt. Your output file should contain one line withone integer: the greatest number of tulips you can save.

Page 5: AIO Senior 2014

Australian Informatics Olympiad 2014 (Senior) — Giant Hippos 4

Sample Input 1

9 3 3

2

5

7

Sample Input 2

7 2 1

1

7

Sample Output 1

4

Sample Output 2

0

Explanation

In the first sample case, as illustrated above, if we put a fence between tulips 2 and 3, betweentulips 4 and 5 and between tulips 7 and 8, no hippo will be able to reach tulips 3, 4, 8 or 9. Thereis no placement of fences that will save more tulips, so 4 is the correct answer.

In the second sample case, no matter where you place the one fence you will not be able to saveany tulips.

Constraints

To evaluate your solution, the judges will run your program against several different input files.All of these files will adhere to the following bounds:

• 1 ≤ N ≤ 1 000 000

• 1 ≤ H ≤ 1 000 and H ≤ N

• 1 ≤ F < N

As some of the test cases will be quite large, you may need to think about how well your solutionscales for larger input values. However, not all the cases will be large. In particular:

• For 50% of the available marks, H = F = 3.

Page 6: AIO Senior 2014

Australian Informatics Olympiad 2014 (Senior) — Chimera 5

Problem 2

Chimera

Input File: chimin.txt

Output File: chimout.txt

Time Limit: 1 second

Next week is your school’s Mad Science Fair, and everyone is hard at work on their mad scienceprojects. For example, Gru is building a rocket big enough to steal the moon, whilst Elsa istinkering with her freeze ray. For your project, you are breeding a chimera.

A chimera is a monster that is part lion, part snake, and part goat. Your plan is to take theDNA sequences of each of the three creatures and combine them into a new DNA sequence for thechimera. A DNA sequence is a string of N letters, each one of A, T, C or G.

?

G A T T A T A

C A G G A T A

T A T T A C A

C A T T A T A

The list above shows an example of three DNA sequences of length 7 representing lion, snakeand goat DNA. The bottom DNA sequence is one possible sequence of chimera’s DNA. Letters inbold in the top three lines are the same as the letter in the chimera’s DNA at the same position.

The lionishness of your chimera is defined as the number of positions in which the lion DNAand the chimera DNA have the same letter. In the example above, the lionishness of your chimerais 6, as they match in all but the first position. The snakiness and goatism of your chimera aredefined similarly. In the example above, the snakiness and goatism of your chimera are both 5.

The task before you is to construct the chimera’s DNA sequence. You will be given the DNAsequences for lions, snakes and goats. The mark for your project will be whichever is lowest: thelionishness, snakiness or goatism of your chimera. You must determine the highest mark you canpossibly achieve.

Page 7: AIO Senior 2014

Australian Informatics Olympiad 2014 (Senior) — Chimera 6

Input

Your program should read from the file chimin.txt.

• The first line of input will contain one integer N : the length of each DNA sequence.

• The next three lines will represent lion, snake and goat DNA respectively. Each of these willcontain a sequence of N letters, each one of A, T, C, or G.

Output

Your program should write to the file chimout.txt. Your output file should contain one line withone integer: the highest possible mark you can achieve. (Remember, your mark will be whicheveris lowest: the lionishness, snakiness or goatism of your chimera.)

Sample Input 1

7

GATTATA

CAGGATA

TATTACA

Sample Output 1

5

Explanation

The sample data reflects the case described on the previous page. There is no chimera DNAsequence that will receive a mark higher than 5.

Constraints

To evaluate your solution, the judges will run your program against several different input files.All of these files will adhere to the following bounds:

• 1 ≤ N ≤ 100 000

Furthermore,

• For 30% of available marks, the lion and snake DNA sequences will be exactly the same.

• For 50% of available marks, all DNA sequences will only use the letters A and T.

Page 8: AIO Senior 2014

Australian Informatics Olympiad 2014 (Senior) — Wormhole 7

Problem 3

Wormhole

Input File: wormin.txt

Output File: wormout.txt

Time Limit: 1 second

You are the lead programmer of Wormhole, a widely anticipated computer game. The premiseof Wormhole is rather thrilling: test subject Chaz is trapped in a rectangular grid of orange andblue chambers each containing one cupcake. Chaz chooses a chamber to start in, and then needsto collect all the cupcakes by visiting every chamber at least once. If this is possible the level isconsidered solvable.

The chambers are walled off from each other by thick glass, such that Chaz can only seechambers which are directly north, south, east or west of his current position. Conveniently Chazhas a ’wormhole gun’, which he can use to shoot through the glass into any chamber he can see andso be instantly teleported there. However, a wormhole can only be created between two chambersof different colours. This means that if Chaz is standing in a blue chamber, he can only move toan orange chamber, and vice versa.

That is, Chaz can teleport to another chamber if:

• It is of a different colour to his current chamber.

• It is directly north, south, east or west (i.e. in the same row or column) of his currentchamber.

cc

Arrows indicate possible teleports Chaz can make. From those chambers he may continue to

teleport to other chambers.

You have been stuck in a meeting for hours now where the designers are interested in howmodifications to the chamber colours affect a level. Each modification involves changing the colourof one chamber. After each change they make, the designers want to know how many moremodifications are needed to make the level solvable – that is, the smallest number of chambersthat need to have their colour changed so that Chaz can reach every chamber from a startingchamber of his choosing.

As working everything out by hand gets more and more tedious, you escape from the meetingand whip out your trusty laptop to write a computer program that will answer the designers’questions after each modification.

Page 9: AIO Senior 2014

Australian Informatics Olympiad 2014 (Senior) — Wormhole 8

Input

Your program should read from the file wormin.txt.

• The first line of input contains three space-separated integers, R, C, and Q. There will beR rows and C columns in the grid, and Q modifications made by the designers.

• The next R lines each contain C characters, representing the initial design of the game. An‘O’ represents an orange chamber, while a ‘B’ represents a blue chamber.

• The following Q lines each contain two integers ri and ci. This represents a modification tothe grid that changes the colour of the chamber in row ri and column ci. Rows are labelledfrom 1 to R (from top to bottom) and columns are labelled from 1 to C (from left to right).

Output

Your program should write to the file wormout.txt. The output should contain Q+ 1 lines. Thefirst line should contain the smallest number of modifications required to make the level solvable.The next Q lines should correspond to the Q modifications in input. After each modification hasbeen made (including all previous modifications), your program should write one line containingthe smallest number of modifications required to make the level solvable (or 0 if it is alreadysolvable).

Sample Input 1

5 5 2

BBBOB

BOBOB

OBBOB

BBBOB

OOOOB

2 2

2 4

Sample Output 1

0

0

1

Explanation

The left image is the inital grid (with blue chambers represented by gray and orange chambersrepresented by white). It is already solvable – there exists a sequence of valid moves starting fromsome chamber that will visit every chamber at least once. After the first modification, the grid(the middle image) is still solvable. After the second modification, as shown on the right, the gridis no longer solvable but by reversing the modification it can be made solvable again.

Page 10: AIO Senior 2014

Australian Informatics Olympiad 2014 (Senior) — Wormhole 9

Sample Input 2

5 6 3

OOBBBO

OOOOOO

OOBBBO

OOOOBO

BOBOBO

3 4

4 5

1 6

Sample Output 2

1

1

2

1

Constraints

To evaluate your solution, the judges will run your program against several different input files.All of these files will adhere to the following bounds:

• 1 ≤ R,C ≤ 300

• 1 ≤ Q ≤ 10 000

For 50% of test cases, 1 ≤ R,C ≤ 50 and 1 ≤ Q ≤ 5000.

Furthermore, your program will be given 50% of available marks for a test case if it correctly

distinguishes between solvable and unsolvable grids (that is, you will be marked on whethereach line of output is 0 or non-zero).