Author: | NEERC-2008 Jury | |||
Input file: | aerodynamics.in | Time limit: | 2 sec | |
Output file: | aerodynamics.out | Memory limit: | 64 Mb |
Bill is working in a secret laboratory. He is developing missiles for national security projects. Bill is the head of the aerodynamics department.
One surprising fact of aerodynamics is called Whitcomb area rule. An object flying at high-subsonic speeds develops local supersonic airflows and the resulting shock waves create the effect called wave drag. Wave drag does not depend on the exact form of the object, but rather on its cross-sectional profile. Consider a coordinate system with OZ axis pointing in the direction of object's motion. Denote the area of a section of the object by a plane z=z0 as S(z0). Cross-sectional profile of the object is a function S that maps z0 to S(z0). There is a perfect aerodynamic shape called Sears-Haack body. The closer cross-sectional profile of an object to the cross-sectional profile of Sears-Haack body, the less wave drag it introduces. That is an essence of Whitcomb area rule. Bill's department makes a lot of computer simulations to study missile's aerodynamic properties before it is even built. To approximate missile's cross-sectional profile one takes samples of S(z0) for integer arguments z0 from zmin to zmax. Your task is to find the area S(z0) for each integer z0 from zmin to zmax, inclusive, given the description of the missile. The description of the missile is given to you as a set of points. The missile is the minimal convex solid containing all the given points. It is guaranteed that there are four points that do not belong to the same plane.4 ≤ n ≤ 100
0 ≤ zmin ≤ zmax ≤ 100
No. | Input file (aerodynamics.in ) |
Output file (aerodynamics.out ) |
---|---|---|
1 |
|
|
Author: | ACM ICPC NEERC 2008 Jury | Roman Elizarov | |||
Input file: | standard input | Time limit: | 2 sec | |
Output file: | standard output | Memory limit: | 256 Mb |
ВНИМАНИЕ: на момент добавления задачи CATS не поддерживала интерактивные задачи. Поэтому проверка решений по этой задаче не производится.
This is an interactive problem.
Your task is to write a program that controls a robot which blindly walks through a maze. The maze is n × m (1 ≤ n, m ≤ 30) rectangular grid that consists of square cells. Each cell is either empty or blocked. All cells on the border of the maze are blocked. The robot starts in an empty cell. It can move south, west, north, or east to an adjacent empty cell. The robot is blind and has only bump sensors, so when it attempts to move it can either succeed or bump into blocked cell and fail.
The robot has to visit all empty cells in the maze. All cells are guaranteed to be reachable.
The picture shows sample maze where blocked cells are, filled and initial robot's location is designated with a circle.
The program must write to the standard output one line with robot's action and wait for a line in the standard input with a response, then write next action and read next response, and so on until all empty cells in the maze had been visited. The program must exit only when all cells have been visited. Empty cells may be visited multiple times. It is acceptable to move even after all cells had been visited.
Each line of the standard input represents response on robot's action. It is either a string \t{EMPTY} if robot has successfully moved in the specified direction to an adjacent cell or a string \t{BLOCKED} if robot's movement has failed because the corresponding adjacent cell was blocked.
Each line of the standard output represents robot's action. It is one of the following five strings: \t{SOUTH}, \t{WEST}, \t{NORTH}, \t{EAST}, or \t{DONE}. \t{DONE} must be printed when the robot has visited all empty cells. After printing \t{DONE} your program must exit. You must flush standard output after printing each action.
No. | Input file (standard input ) |
Output file (standard output ) |
---|---|---|
1 |
|
|
Author: | NEERC-2008 Jury | |||
Input file: | clock.in | Time limit: | 2 sec | |
Output file: | clock.out | Memory limit: | 64 Mb |
One famous Russian architect plans to build a new monumental construction. It will be a huge clock that indicates the time from the beginning of the universe.
The face of this clock contains hands, moving at constant speeds. They are numbered from 1 to n from the fastest to the slowest one. The fastest hand makes one revolution per minute (60 seconds). Each next hand moves slower than previous, the (i+1)-th hand makes one revolution when the i-th hand makes di revolutions. The setting mechanism of this clock is very simple. You can take a hand by the handle, located on its end, and move it in any direction. When you move the hand, slower hands are moving in proportion to their usual speeds, and faster hands are not moving. Remember that hands are huge, so setting this clock is a hard job. Consider an example with three hands: a second hand, a minute hand, and an hour hand. Their lengths are 5, 15 and 10 meters respectively. You want to set the clock from 2:30 to 6:00 (fig.1). The easiest way to do it is to rotate the minute hand 180∘ clockwise, and then move the hour hand 90∘ clockwise. The total distance you moved the handles of the hands is approximately 62.83 meters. Your task is to write a program that finds the way to set the clock that minimizes the total distance you have to move the handles.0 < n ≤ 50
2 ≤ di ≤ 106
1 ≤ li ≤ 106
No. | Input file (clock.in ) |
Output file (clock.out ) |
---|---|---|
1 |
|
|
Author: | NEERC-2008 Jury | |||
Input file: | drive.in | Time limit: | 2 sec | |
Output file: | drive.out | Memory limit: | 256 Mb |
MegaCity of the future is a rectangular grid of streets. Each intersection has integer Cartesian coordinates x and y. To get from intersection a with coordinates xa, ya to intersection b with coordinates xb, yb you need to drive exactly |xa−xb| + |ya−yb| blocks. Usually, it takes 10 time units to drive one block, so one can easily compute the time it takes to get from a to b. However, traffic jams that occur in MegaCity turn estimation of minimal driving time into a complex problem that you have to solve.
Traffic jams in MegaCity affect a rectangular area that is specified by coordinates of its bottom-left and top-right corners. The time to travel one block in the traffic jam is specified. All streets that are strictly inside the rectangular region are affected by the traffic jam. Sometimes, it is better to drive around the traffic jams to save time, but sometimes it is better to drive through some traffic jams as shown in the example — 17 blocks are driven outside of traffic jams, taking 10 time units per block, and 2 blocks in the light traffic jam with 11 time units per block.0 ≤ n ≤ 1000
(x1,i < x2,i, y1,i < y2,i)
10 < ti ≤ 108
All coordinates in the input file are from 0 to 108 inclusive. Areas of traffic jams neither intersect nor touch each other. Start and finish points are different and do not lie inside nor on the border of any traffic jam.
No. | Input file (drive.in ) |
Output file (drive.out ) |
---|---|---|
1 |
|
|
Author: | NEERC-2008 Jury | |||
Input file: | exclusive.in | Time limit: | 2 sec | |
Output file: | exclusive.out | Memory limit: | 64 Mb |
One important problem in concurrent programming is to ensure exclusive access to shared resources by multiple threads. It is also known as Mutual Exclusion protocol. A code that needs to be protected from concurrent execution is called critical section (CS). In order to coordinate access to CS, application threads use a set of shared variables to send information to each other. These shared variables are distinct from all the variables that are used by application code. In practice, mutual exclusion protocol is implemented as two methods — enterCS and exitCS. When application needs to execute some code in CS, it calls enterCS, then executes CS, then calls exitCS.
For theoretical analysis of mutual exclusion protocol one must consider running application as a whole. Each thread of application is represented as an infinite loop that repeatedly performs some work unrelated to CS, which is called non-critical section (NCS), then calls enterCS, then executes CS, then calls exitCS, then the loop repeats. The code inside NCS and CS is not relevant; it is considered to perform no operations related to the protocol and does not modify shared variables used by the protocol.
We consider a system with two concurrently running threads. Threads use a set of shared one-bit variables to implement mutual exclusion protocol. Each variable can store a value of zero or one that can be read or written by a single instruction. Shared variables are initialized to zero. Each thread has a local pointer to the instruction (IP) that it is going to execute next. Execution starts from the top of the code. During each step of execution one of the threads is arbitrarily chosen, it executes one instruction, and then changes its IP to the next instruction to execute. This infinite sequence of steps is called history. A history is called legal if either both threads execute infinitely many steps or just one thread does, while the other thread, having taken a finite number of steps, stops with IP at NCS.
The table below contains several algorithms in pseudo-code that attempt to implement mutual exclusion protocol. In this pseudo-code id is 0 for the first thread and 1 for the second. Variables want[0], want[1], and turn are shared between threads to implement mutual exclusion protocol. Lines marked with "\verb|+|" implement enterCS, lines marked with "\verb|-|" implement exitCS. Lines NCS() and CS() are placeholders for some code that works inside non-critical and critical sections respectively and is not relevant for this problem.
The task is to figure out if the given algorithm satisfies three important properties:
The property of mutual exclusion is trivial. The algorithm that simply loops forever doing nothing will satisfy it. The sample algorithms above all satisfy mutual exclusion, but the first two fail to achieve deadlock freedom. The algorithm 3 (originally created by Gary Peterson) satisfies all three properties.
The input file starts with a line with two integer numbers — m1 and m2, where mi is the number of lines of code for i-th thread (2 ≤ mi ≤ 9). It is followed by m1 lines with the code for the first thread and m2 lines with the code for the second thread.
The code for each thread contains one instruction per line. Instruction starts with an integer line number from 1 to mi (lines are numbered in ascending order and are included to aid readability), followed by instruction mnemonic, followed by a list of instruction arguments, all separated by spaces. The last arguments of instruction represent line numbers of the next instructions to execute (NIP — from 1 to mi). There are three variables shared between threads — A, B, and C. Instruction mnemonics are:No. | Input file (exclusive.in ) |
Output file (exclusive.out ) |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
Author: | ACM ICPC NEERC 2008 Jury | |||
Input file: | fibonacci.in | Time limit: | 2 sec | |
Output file: | fibonacci.out | Memory limit: | 256 Mb |
Author: Anton Maydell Text: Andrew Lopatin Tests: Anton Maydell
Little John studies numeral systems. After learning all about fixed-base systems, he became interested in more unusual cases. Among those cases he found a Fibonacci system, which represents all natural numbers in an unique way using only two digits: zero and one. But unlike usual binary scale of notation, in the Fibonacci system you are not allowed to place two \t{1}s in adjacent positions.
One can prove that if you have number N = an an−1… a1F in Fibonacci system, its value is equal to N = an ⋅ Fn + an−1 ⋅ Fn−1 + … + a1 ⋅ F1, where Fk is a usual Fibonacci sequence defined by F0=F1=1, Fi=Fi−1+Fi−2.
For example, first few natural numbers have the following unique representations in Fibonacci system:
1 = 1F, 2 = 10F, 3 = 100F, 4 = 101F, 5 = 1000F, 6 = 1001F, 7 = 1010F,
John wrote a very long string (consider it infinite) consisting of consecutive representations of natural numbers in Fibonacci system. For example, the first few digits of this string are 110100101100010011010...
He is very interested, how many times the digit \t{1} occurs in the N-th prefix of the string. Remember that the N-th prefix of the string is just a string consisting of its first N characters.
Write a program which determines how many times the digit 1 occurs in N-th prefix of John's string.
The input file contains a single integer N (0≤ N≤ 1015).
Output a single integer — the number of 1s in N-th prefix of John's string.
No. | Input file (fibonacci.in ) |
Output file (fibonacci.out ) |
---|---|---|
1 |
|
|
Author: | ACM ICPC NEERC 2008 Jury | Roman Elizarov | |||
Input file: | giant.in | Time limit: | 2 sec | |
Output file: | giant.out | Memory limit: | 256 Mb |
You are working in Advanced Computer Monitors (ACM), Inc. The company is building and selling giant computer screens that are composed from multiple smaller screens. Your are responsible for design of the screens for your customers.
Customers order screens of the specified horizontal and vertical resolution in pixels and a specified horizontal and vertical size in millimeters. Your task is to design a screen that has a required resolution in each dimension or more, and has required size in each dimension or more, with a minimal possible price. The giant screen is always built as a grid of monitors of the same type. The total resolution, size, and price of the resulting screen is simply the sum of resolutions, sizes, and prices of the screens it is built from.
You have a choice of regular monitor types that you can order and you know their resolutions, sizes, and prices. The screens of each type can be mounted both vertically and horizontally, but the whole giant screen must be composed of the screens of the same type in the same orientation. You can use as many screens of the chosen type as you need.
The first line of the input file contains four integer numbers rh, rv, sh, and sv (all from 100 to 104 inclusive) — horizontal and vertical resolution and horizontal and vertical size of the screen you have to build, respectively. The next line contains a single integer number n (1 ≤ n ≤ 100) — the number of different screen types available to you. The next n lines contain descriptions of the available screen types. Each description occupies one line and consists of five integer numbers — rh,i, rv,i, sh,i, sv,i, pi (all from 100 to 10\,000 inclusive), where first four numbers are horizontal and vertical resolution and horizontal and vertical size of i-th screen type, and pi is the price.
Write to the output file a single integer — the minimal price of the specified giant screen.
No. | Input file (giant.in ) |
Output file (giant.out ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | ACM ICPC NEERC 2008 Jury | Roman Elizarov (original text), Georgiy Korneev (editing) | |||
Input file: | hell.in | Time limit: | 2 sec | |
Output file: | hell.out | Memory limit: | 256 Mb |
Most financial institutions had become insolvent during financial crisis and went bankrupt or were bought by larger institutions, usually by banks. By the end of financial crisis of all the financial institutions only two banks still continue to operate. Financial markets had remained closed throughout the crisis and now regulators are gradually opening them. To prevent speculation and to gradually ramp up trading they will initially allow trading in only one financial instrument and the volume of trading will be limited to i contracts for i-th minute of market operation.
Two banks had decided to cooperate with the government to kick-start the market operation. The boards of directors had agreed on trading volume for each minute of this first trading session. One bank will be buying ai contracts (1 ≤ ai ≤ i) during i-th minute (1 ≤ i ≤ n), while the other one will be selling. They do not really care whether to buy or to sell, and the outside observer will only see the volume ai of contracts traded per minute. However, they do not want to take any extra risk and want to have no position in the contract by the end of the trading session. Thus, if we define bi = 1 when the first bank is buying and bi = −1 when the second one is buying (and the first one is selling), then the requirement for the trading session is that ∑ni=1ai bi = 0.
Your lucky team of three still works in the data center (due to the crisis, banks now share the data center and its personnel) and your task is to find such bi or to report that this is impossible.
The first line of the input file contains the single integer number n (1 ≤ n ≤ 105).
The second line of the input file contains n integer numbers — ai (1 ≤ ai ≤ i).
The first line of the output file must contain "Yes" if the trading session with specified volumes is possible and "No" otherwise. In the former case the second line must contain n numbers — bi.
No. | Input file (hell.in ) |
Output file (hell.out ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | ACM ICPC NEERC 2008 Jury | Roman Elizarov | |||
Input file: | isharp.in | Time limit: | 2 sec | |
Output file: | isharp.out | Memory limit: | 256 Mb |
You are developing a new fashionable language that is not quite unlike C, C++, and Java. Since your language should become an object of art and fashion, you call it i# (spelled i-sharp). This name combines all the modern naming trends and also hints at how smart you are.
Your language caters for a wide auditory of programmers and its type system includes arrays (denoted with "[]"), references (denoted with "&"), and pointers (denoted with "*"). Those type constructors can be freely combined in any order, so that a pointer to an array of references of references of integers (denoted with "int&&[]*") is a valid type.
Multiple variables in i# can be declared on a single line with a very convenient syntax where common type of variables is given first, followed by a list of variables, each optionally followed by additional variable-specific type constructors. For example, the following line:
int& a*[]&, b, c*;
declares variables a, b, and c with types int&&[]*, int&, and int&* correspondingly. Note, that type constructors on the right-hand sides of variables in i# bind to variable and their order is reversed when they are moved to the left-hand side next to type. Thus int*& a is equivalent to int a&*.
However, you discover that coding style with multiple variable declarations per line is confusing and is outlawed in many corporate coding standards. You decide to get rid of it and refactor all existing i# code to a single variable declaration per line and always specify type constructor next to the type it refers to (instead of the right-hand side of variable). Your task it to write such refactoring tool.
The input file contains a single line with a declaration of multiple variables in i#. The line starts with a type name, followed by zero, one, or more type constructors, followed by a space, followed by one or more variable descriptors separated by "," (comma) and space, and terminated by ";" (semicolon). Each variable descriptor contains variable name, followed by zero, one, or more type constructors.
Type name and variable names are distinct and consist of lowercase and uppercase English letters from a to z or A to Z. The line contains at most 120 characters and does not contain any extra spaces.
Write to the output file a line for each variable declared in the input file. For each variable write its declaration on a single line in the same format as in the input file, but with all type constructors next to its type. Separate type with all type constructors from a variable name by a single space. Do not write any extra spaces.
No. | Input file (isharp.in ) |
Output file (isharp.out ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | ACM ICPC NEERC 2008 Jury | Mikhail Dvorkin | |||
Input file: | javanese.in | Time limit: | 2 sec | |
Output file: | javanese.out | Memory limit: | 256 Mb |
Javanese is the language of the people in the Central and Eastern parts of the island of Java, Indonesia.
In 1926, a standard orthography using the English Alphabet was created for the Javanese language. This writing system uses all letters from A to Z. The five letters A, E, I, O, and U are vowels, while all other letters are consonants. In Javanese words vowels and consonants always alternate. This property is quite useful when deciphering encrypted Javanese texts.
A text s consists of words, each word contains only capital letters. Let's call text s legitimate if in each word of s vowels and consonants alternate (no two vowels and no two consonants are located next to each other).
A simple substitution cipher is applied to a text s. That is, a bijection f: A ↦ A is chosen, where A is the set of capital letters. The encoded text t is obtained from s by substituting each letter c with f(c).
You're given the encoded text t. Find any legitimate text s that can be encoded as t, or detect that there is no such legitimate s.
The input file contains the encoded text t, a list of words separated by spaces and/or line breaks. Each word consists only of capital letters (A to Z).
The input file contains no more than 105 characters.
If the text t cannot be an encoded legitimate text, output only one word "impossible".
Otherwise, output any legitimate text s that can be encoded into t. Separate words of s with spaces and/or line breaks. All letters in s should be capital.
No. | Input file (javanese.in ) |
Output file (javanese.out ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | ACM ICPC NEERC 2008 Jury | Georgiy Korneev (idea and original text), Mikhail Dvorkin (final text) | |||
Input file: | kina.in | Time limit: | 2 sec | |
Output file: | kina.out | Memory limit: | 256 Mb |
When introducing new terms consisting of several words, it is useful to use abbreviations. An abbreviation is a word that consists of the first letters of several consecutive words.
An abbreviation is called unambiguous if the following two conditions are satisfied:
For example, in the text "A recursive acronym KINA means "KINA is not abbreviation", strings "ARA" and "K" are unambiguous abbreviations, strings "A" and "KINA" are ambiguous abbreviations, and strings "RAA" and "KNA" are not abbreviations.
To introduce an abbreviation in a text, it is placed in parentheses right after the sequence of words it corresponds to. Future occurrences of this sequence of words can be replaced by the abbreviation. In the example text above, introduction of the abbreviation "K" produces the following text: "A recursive acronym KINA (K) means "K is not abbreviation"".
If two occurrences of a sequence of words overlap, only one of them can be replaced by the abbreviation. Words in a sequence are separated by one or more non-alphabetic characters. Comparison of words is case-insensitive. For example, "i18n" is an occurrence of the word sequence "I n".
The effectiveness of an abbreviation is the decrease in the number of letters after introduction of this abbreviation. Only letters are taken into account; spaces, parentheses and all other non-alphabetical characters do not count.
Given a text, find an unambiguous abbreviation with the maximum effectiveness.
The input file contains a text with at most 4000 characters. The text contains only characters with ASCII codes 32 (space) to 126 ("~"), 13 (carriage return), and 10 (line feed).
If there is no unambiguous abbreviation with positive effectiveness, then the output file should contain the single number 0.
Otherwise, the first line of the output file should contain the effectiveness of the optimal abbreviation. The second line should contain the unambiguous abbreviation itself. If there are multiple unambiguous abbreviations with the maximum effectiveness, output any one of them.
No. | Input file (kina.in ) |
Output file (kina.out ) |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|