Problem A. Consonants
Small input 8 points | |
Large input 20 points |
Problem
In English, there are 26 letters that are either vowels or consonants. In this problem, we consider a, e, i, o, and u to be vowels, and the other 21 letters to be consonants.
A tribe living in the Greatest Colorful Jungle has a tradition of naming their members using English letters. But it is not easy to come up with a good name for a new member because it reflects the member's social status within the tribe. It is believed that the less common the name he or she is given, the more socially privileged he or she is.
The leader of the tribe is a professional linguist. He notices that hard-to-pronounce names are uncommon, and the reason is that they have too many consecutive consonants. Therefore, he announces that the social status of a member in the tribe is determined by its
All members in the tribe must have their names and n given by the leader. Although the leader is a linguist and able to ensure that the given names are meaningful, he is not good at calculating the
Input
The first line of the input gives the number of test cases, T. T test cases follow. The first line of each test case gives the name of a member as a string of length L, and an integer n. Each name consists of one or more lower-case English letters.
Output
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the
Limits
1 ≤ T ≤ 100.
0 < n ≤ L.
Small dataset
1 ≤ L ≤ 100.
Large dataset
1 ≤ L ≤ 106.
The input file will be no larger than 6MB.
Sample
Input |
Output |
4
|
Case #1: 4
|
Small input 10 points | |
Large input 25 points |
Problem
You have just got the best gift ever, a Pogo stick. The pogo stick is something you use to jump off the ground while standing on it.
This Pogo stick is a special one: the first jump will move you a distance of 1 unit, the second jump will move you 2 units, the third jump will move you 3 units and so on. You can jump in only four directions using this stick: north (increasing y), south (decreasing y), east (increasing x) or west (decreasing x).
Now you want to play a game in your backyard, which we model as an infinite plane. You are standing with your stick in at point (0, 0) and you want to go to point (X, Y).
The point (X, Y) will never be (0, 0), and it will always be reachable from your starting point.
Check the output section carefully, because the required outputs for the small and large datasets are not the same.
Input
The first line of the input gives the number of test cases, T. T test cases follow, one per line. Each line consists of 2 integers separated by a single space, X and Y, the coordinates of the point you want to reach.
Output
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is a string represents the directions of the moves, for example if you are going to move north then south then east then west, this string should be NSEW.
For the small dataset, the output is considered correct if it does not take more than 500 moves to reach the destination in each test case.
For the large dataset, the output is considered correct if it reaches the destination point in the minimum possible number of moves.
If there are multiple correct solutions, print any of them.
Limits
Small dataset
1 ≤ T ≤ 50.
0 ≤ |X|, |Y| ≤ 100.
Large dataset
1 ≤ T ≤ 100.
0 ≤ |X|, |Y| ≤ 106.
Sample
Input |
Output |
2
|
Case #1: ENWSEN
|
Small input 9 points | |
Large input 28 points |
Problem
You are studying the history of the Great Wall of China, which was built by the Chinese to protect against military incursions from the North. For the purposes of this problem, the Great Wall stretches from infinity in the East to minus infinity in the West. As this is a lot of distance to cover, the Great Wall was not built at once. Instead, for this problem we assume that the builder used a reactive strategy: whenever a part of the border was attacked successfully, the Wall on this part of the border would be raised to the height sufficient to stop an identical attack in the future.
The north border of China was frequently attacked by nomadic tribes. For the purposes of this problem, we assume that each tribe attacks the border on some interval with some strength S. In order to repel the attack, the Wall must have height S all along the defended interval. If even a short stretch of the Wall is lower than needed, the attack will breach the Wall at this point and succeed. Note that even a successful attack does not damage the Wall. After the attack, every attacked fragment of the Wall that was lower than S is raised to height S — in other words, the Wall is increased in the minimal way that would have stopped the attack. Note that if two or more attacks happened on the exact same day, the Wall was raised only after they all resolved, and is raised in the minimum way that would stop all of them.
Since nomadic tribes are nomadic, they did not necessarily restrict themselves to a single attack. Instead, they tended to move (either to the East or to the West), and periodically attack the Wall. To simplify the problem, we assume they moved with constant speed and attacked the Wall at constant intervals; moreover we assume that the strength with which a given tribe attacked the Wall changed by a constant amount after each attack (either decreased from attrition, or grew from experience).
Assuming that initially (in 250 BC) the Wall was nonexistent (i.e., of height zero everywhere), and given the full description of all the nomadic tribes that attacked the Wall, determine how many of the attacks were successful.
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with a line containing a single integer N: the number of the tribes attacking the Wall. N lines follow, each describing one tribe. The ith line contains eight integers di, ni, wi, ei, si, delta_di, delta_pi and delta_si separated by spaces, describing a single nomadic tribe:
- di – the day of the tribe's first attack (where 1st January, 250BC, is considered day 0)
- ni – the number of attacks from this tribe
- wi, ei – the westmost and eastmost points respectively of the Wall attacked on the first attack
- si – the strength of the first attack
- delta_di – the number of days between subsequent attacks by this tribe
- delta_pi – the distance this tribe travels to the east between subsequent attacks (if this is negative, the tribe travels to the west)
- delta_si – the change in strength between subsequent attacks
Output
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of attacks that succeed.
Limits
1 ≤ T ≤ 20.
0 ≤ di.
1 ≤ delta_di ≤ 676060.
di + (ni - 1) * delta_di ≤ 676060.
1 ≤ si ≤ 106.
-105 ≤ delta_si ≤ 105.
si + (ni - 1) * delta_si ≥ 1.
Small dataset
1 ≤ N ≤ 10.
1 ≤ ni ≤ 10.
-100 ≤ wi < ei ≤ 100.
-10 ≤ delta_pi ≤ 10.
Large dataset
1 ≤ N ≤ 1000.
1 ≤ ni ≤ 1000.
-106 ≤ wi < ei ≤ 106.
-105 ≤ delta_pi ≤ 105.
Sample
Input |
Output |
2
|
Case #1: 5
|
In the first case, the first tribe attacks three times: on day 0 it hits the interval [0,2] at height 10, on day 2 it hits [3,5] at height 8 and on day 4 it hits [6,8] at height 6; all three attacks succeed. Then the second tribe attacks three times, each time at height 8 - on day 10 it hits [2,3] (this succeeds, for example at position 2.5, where the Wall has still height 0), on day 17 it hits [4,5] (this fails, the Wall is already of height 8 in the interval [3, 5], which covers [4, 5]), and on day 24 it hits [6,7] (this succeeds, as the Wall there was of height 6).
In the second case there are three tribes, and their attacks intermingle. The sequence is as follows:
- On day 0, Tribe 2 attacks [0,1] at height 7 and succeeds.
- On day 1, Tribe 1 attacks [0,5] at height 10, and Tribe 2 attacks [2,3] at height 9. Both attacks succeed (as they were simultaneous, the Wall built after the attack of the first tribe isn't there in time to stop the second tribe).
- On day 2, Tribe 2 attacks [4,5] at height 11 and succeeds (the Wall there was at height 10).
- On day 3, Tribe 1 attacks [8,13] at height 10 and succeeds. Simultaneously, Tribe 3 attacks [0,5] at height 1 and fails (there's a Wall of heights 10 and 11 there).
- On day 4 Tribe 3 attacks [4,9] at height 1 and succeeds (there was no Wall between 5 and 8).
- Finally, on day 5 Tribe 3 attacks [8,13] at height 1 and fails (since a Wall of height 10 is there).
The last Round 1 again had an attendance in the vicinity of 5000 — pretty impressive, given that 2000 people already advanced. Our contestants were faced with a substring-counting problem Consonants, where to solve the large you had to deal with million-character names; followed by the tricky puzzle of Pogo and an implementation-intense problem called Great Wall.
The large input size in consonants caused the solutions of a large number of contestants to time out — quadratic solutions weren't cutting it, after all, and nearly 60% of contestants who attempted the large failed. The large of pogo was even more tricky — while for the small you could do some variation around exhaustive search, for the large you needed a few observations to come up with a greedy solution. Only 19% of contestants who attacked this problem succeeded. Finally, the Great Wall had a rather complex input that scared many people off, the first submission for the small came over half an hour into the contest; and the large required some variation on the theme of interval trees.
The competition was off to a blazing start, with xiaowuc1 solving the small of Consonants in an astounding time below two minutes! The other problems proved more problematic, however. In the end, it turned out that solving any one problem by itself was not enough to advance. The most popular way to get a spot in Round 2 was to deal with Consonants large and both remaining smalls, followed by dropping the Great Wall small in favor of doing the other problems really fast.
Congratulations to everybody who got through to Round 2, and we hope you enjoyed all the Round 1 problems!
Cast
Problem A. Consonants written by Khaled Hafez and Petr Mitrichev. Prepared by Onufry Wojtaszczyk and Hackson Leung.
Problem B. Pogo written by David Arthur. Prepared by Onufry Wojtaszczyk and Ahmed Aly.
Problem C. The Great Wall written by Onufry Wojtaszczyk. Prepared by Adrian Kuegel and Steve Thomas.
Contest analysis presented by Onufry Wojtaszczyk, John Dethridge and Hackson Leung. Solutions and other problem preparation by Igor Naverniouk, Jan Kuipers, Tomek Czajka and Tomek Kulczynski.
Category | Asked | Question | Answered | Answer | ||||
---|---|---|---|---|---|---|---|---|
The Great Wall Announcement | 50:35 | For Tribe 1 on the second sample case, it seems that n1==1. Then, why is there second attack of Trive 1 for [8,13] at height 10 on day 3? | 1:14:36 | n1 in the second test case should be 2, and the statement is updated so the details for the first Tribe is "1 2 0 5 10 2 8 0" instead of "1 1 0 5 10 2 8 0". The statement is updated, sorry. |