| IOI archive |
|---|
| Private |
| Spectator |
| IOI 2014 day 2 |
|---|
| Finished |
Mao-Kong Gondola is a famous attraction in Taipei. The gondola system consists of a circular rail, a single station, and $$$n$$$ gondolas numbered consecutively from $$$1$$$ to $$$n$$$ running around the rail in a fixed direction. After gondola $$$i$$$ passes the station, the next gondola to pass the station will be gondola $$$i + 1$$$ if $$$i \lt n$$$, or gondola 1 if $$$i = n$$$.
Gondolas may break down. Luckily we have an infinite supply of spare gondolas, which are numbered $$$n + 1, n + 2$$$, and so on. When a gondola breaks down we replace it (in the same position on the track) with the first available spare gondola, that is, the one with the lowest number. For example, if there are five gondolas and gondola 1 breaks down, then we will replace it with gondola 6.
You like to stand at the station and watch the gondolas as they pass by. A gondola sequence is a sequence of $$$n$$$ numbers of gondolas that pass the station. It is possible that one or more gondolas broke down (and were replaced) before you arrived, but none of the gondolas break down while you are watching.
Note that the same configuration of gondolas on the rail can give multiple gondola sequences, depending on which gondola passes first when you arrive at the station. For example, if none of the gondolas have broken down then both $$$(2, 3, 4, 5, 1)$$$ and $$$(4, 5, 1, 2, 3)$$$ are possible gondola sequences, but $$$(4, 3, 2, 5, 1)$$$ is not (because the gondolas appear in the wrong order).
If gondola $$$1$$$ breaks down, then we might now observe the gondola sequence $$$(4, 5, 6, 2, 3)$$$. If gondola $$$4$$$ breaks down next, we replace it with gondola $$$7$$$ and we might observe the gondola sequence $$$(6, 2, 3, 7, 5)$$$. If gondola $$$7$$$ breaks down after this, we replace it with gondola $$$8$$$ and we may now observe the gondola sequence $$$(3, 8, 5, 6, 2)$$$.
| Broken gondola | New gondola | Possible gondola sequence |
| 1 | 6 | $$$(4, 5, 6, 2, 3)$$$ |
| 4 | 7 | $$$(6, 2, 3, 7, 5)$$$ |
| 7 | 8 | $$$(3, 8, 5, 6, 2)$$$ |
A replacement sequence is a sequence consisting of the numbers of the gondolas that have broken down, in the order in which they break down. In the previous example the replacement sequence is $$$(1, 4, 7)$$$. A replacement sequence $$$r$$$ produces a gondola sequence $$$g$$$ if, after gondolas break down according to the replacement sequence $$$r$$$, the gondola sequence $$$g$$$ may be observed.
Gondola Sequence Checking
In the first three subtasks you must check whether an input sequence is a gondola sequence. See the table below for examples of sequences that are and are not gondola sequences. You need to implement a function valid.
Replacement Sequence
In the next three subtasks you must construct a possible replacement sequence that produces a given gondola sequence. Any such replacement sequence will be accepted. You need to implement a function replacement.
Count Replacement Sequences
In the next four subtasks you must count the number of possible replacement sequences that produce a given sequence (which may or may not be a gondola sequence), modulo $$$1\,000\,000\,009$$$. You need to implement a function countReplacement.
The sample grader reads the input in the following format:
The sample grader prints the following output:
If subtask is 1, 2 or 3
If subtask is 4, 5 or 6
If subtask is 7, 8, 9 or 10
| Subtask | Points | n | inputSeq |
| 1 | 5 | $$$n \le 100$$$ | has each number from $$$1$$$ to $$$n$$$ exactly once |
| 2 | 5 | $$$n \le 100\,000$$$ | $$$1 \le inputSeq[i] \le n$$$ |
| 3 | 10 | $$$n \le 100\,000$$$ | $$$1 \le inputSeq[i] \le 250\,000$$$ |
| Subtask | Points | n | gondolaSeq |
| 4 | 5 | $$$n \le 100$$$ | $$$1 \le gondolaSeq[i] \le n + 1$$$ |
| 5 | 10 | $$$n \le 1\,000$$$ | $$$1 \le gondolaSeq[i] \le 5\,000$$$ |
| 6 | 20 | $$$n \le 100\,000$$$ | $$$1 \le gondolaSeq[i] \le 250\,000$$$ |
| Subtask | Points | n | inputSeq |
| 7 | 5 | $$$4 \le n \le 50$$$ | $$$1 \le inputSeq[i] \le n + 3$$$ |
| 8 | 15 | $$$4 \le n \le 50$$$ | $$$1 \le inputSeq[i] \le 100$$$, and at least $$$n - 3$$$ of the initial gondolas did not break down. |
| 9 | 15 | $$$n \le 100\,000$$$ | $$$1 \le inputSeq[i] \le 250\,000$$$ |
| 10 | 10 | $$$n \le 100\,000$$$ | $$$1 \le inputSeq[i] \le 1\,000\,000\,000$$$ |
1 30 16 26 18 19 20 13 22 21 24 25 17 27 28 29 30 1 2 3 11 5 6 8 7 9 10 12 4 23 14 15
0
2 6 3 4 5 6 1 2
1
3 7 1 2 3 4 5 6 5
0
4 2 3 2
1 1
5 14 12 13 14 1 2 3 4 5 6 7 8 9 10 11
0
6 50 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 51 47 48 49 50 1 2 3
1 46
7 11 4 5 6 7 8 9 10 11 1 2 3
1
8 14 6 94 8 9 10 93 12 13 95 1 2 3 4 5
224280120
9 4 1 2 7 6
2
10 4 4 7 4 7
0
You have to submit exactly one file, called gondola.cpp. This file should implement all three subprograms described above (even if you only plan to solve some of the subtasks), using the signatures. You also need to include a header file gondola.h for C/C++ implementation.
| Subtask | inputSeq | Return value | Note |
| 1 | $$$(1, 2, 3, 4, 5, 6, 7)$$$ | 1 | — |
| 1 | $$$(3, 4, 5, 6, 1, 2)$$$ | 1 | — |
| 1 | $$$(1, 5, 3, 4, 2, 7, 6)$$$ | 0 | 1 cannot appear just before 5 |
| 1 | $$$(4, 3, 2, 1)$$$ | 0 | 4 cannot appear just before 3 |
| 2 | $$$(1, 2, 3, 4, 5, 6, 5)$$$ | 0 | two gondolas numbered 5 |
| 3 | $$$(2, 3, 4, 9, 6, 7, 1)$$$ | 1 | replacement sequence (5, 8) |
| 3 | $$$(10, 4, 3, 11, 12)$$$ | 0 | 4 4 cannot appear just before 3 |
| Subtask | gondolaSeq | Return value | ReplacementSeq |
| 4 | $$$(3, 1, 4)$$$ | 1 | $$$(2)$$$ |
| 4 | $$$(5, 1, 2, 3, 4)$$$ | 0 | $$$()$$$ |
| 5 | $$$(2, 3, 4, 9, 6, 7, 1)$$$ | 2 | $$$(5, 8)$$$ |
| Subtask | inputSeq | Return value | Replacement sequence |
| 7 | $$$(1, 2, 7, 6)$$$ | 2 | $$$(3, 4, 5)$$$ or $$$(4, 5, 3)$$$ |
| 8 | $$$(2, 3, 4, 12, 6, 7, 1)$$$ | 1 | $$$(5, 8, 9, 10, 11)$$$ |
| 9 | $$$(4, 7, 4, 7)$$$ | 0 | $$$inputSeq$$$ is not a gondola sequence |
| 10 | $$$(3, 4)$$$ | 2 | $$$(1, 2)$$$ or $$$(2, 1)$$$ |
| Name |
|---|


