Author: | A. Klenin | |||
Input file: | input.txt | Time limit: | 1 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
Scientists of Nearsea Institute of Underwater Life obtained a picture of the mysterious aquatic life form. They wanted to determine the creature's species.
To do that, picture copies were distributed among N experts. Each expert made Gi guesses, each guess consisting of the name of the species and the score sij reflecting expert's level of confidence in the guess. For each expert, all guesses name different species.
You program must choose the species which received the highest total score from all experts.
In the first sample below "Ceramaster_arcticus" species received the total score of 14.
Input file contains integer N on the first line, followed by N line blocks — one for each expert.
Each line block contains integer Gi, on the first line, followed by Gi lines — one for each guess.
Each guess line contains an integer sij followed by a string — guess score and species name. Names consist of Latin letters and underscores (ASCII 95). Names are case-sensitive ("a" and "A" are different names).
Output file must contain names of all species with the score equal to the highest total score, one name per line, sorted lexicographically.
1 ≤ N ≤ 100, 1 ≤ Gi ≤ 100, 1 ≤ sij ≤ 100
Species names contain from 1 to 50 characters.
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|
Author: | A. Klenin | |||
Input file: | input.txt | Time limit: | 1 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
The Nearsea Institute of Underwater Studies decided to make a survey of the sea bottom.
The area where the survey takes place is represented by a rectangular grid. The x axis runs from west to east and the y axis runs from south to north.
A robotic underwater vehicle is used to perform the survey. The vehicle has a program which allows him to cover a rectangular part of the sea bottom defined by the coordinates of its south-west and north-east corners.
Initially it was planned for a robot to submerge once and survey a single rectangular area with coordinates (ax, ay) − (bx, by).
Suddenly, a representative of the Ministry of Defense showed up, and declared that the rectangular area with coordinates (cx, cy) − (dx, dy) contains secret military installations, and must not be visited by the vehicle.
It was decided to split the survey area into a smaller rectangles and perform a separate submersion for each of them. Rectangles must not intersect neither the restricted area nor each other and must cover all survey area except the restricted area.
Your program must find the splitting which requires minimal number of submersions.
Input file contains 8 integers ax ay bx by cx cy dx dy.
Output file should contain minimum number of submersions M followed by M groups of 4 integers xi yi ui vi — coordinates of the south-east and north-west corners of the area which should be covered by i-th submersion. If there is more than one optimal solution, output any of them.
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|
Author: | A. Zhuplev, A. Klenin, I. Tufanov | |||
Input file: | input.txt | Time limit: | 1 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
Scientists of the Nearsea Institute of Underwater Mythology are researching the mythical creature called Cthulhu.
The creature is famous for producing many offspring known as Cthulhu spawn. Each spawn has a small round body with N radially protruding appendages. Each appendage is either a tentacle or a claw.
Two spawns are considered identical, if one of them can be rotated in such a way that the sequence of tentacles and claws will coincide with the other spawn.
For example, if we designate tentacle by "T" and claw by "C", spawns "TCTCCT" and "CCTTCT" are identical and different from spawns "TTTCCT" ad "CCTTTC".
You program must, for given N, calculate the total number of different spawns with N appendages.
Input file contains a single integer N.
Output file must contain a single integer — number of different spawns.
1 ≤ N ≤ 58
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | I. Ludov | |||
Input file: | input.txt | Time limit: | 1 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
The great and modern underwater city of R'Lyeh occupies vast area on the ocean floor. It is surrounded by R'Lyeh Ring Road (RRR) which separates business and cultural center from the rest of the city. The road itself is nothing more than a traffic pattern, which all underwater vehicles should obey.
The ocean floor around the city is flat, and vehicles can only crawl, not swim, so the road can be represented by a two-dimensional map.
Denizens of R'Lyeh built their first vehicles based on design brought to them by the famous explorers named Pinky and Brain, who visited R'Lyeh during their expedition to sunken "Titanic".
That design had one shortcoming — the vehicles were only able to turn to the right. Such a bizarre engineering solution had a serious impact on the design of RRR: it is possible to depart from any point on the road, make one or more circles around the business center and return to the starting point place, having visited all the road and making right turns only.
The traffic is one-way everywhere, so driving around R'Lyeh is simple. The only complication is a necessity to pass intersections. When passing an intersection, vehicles must move straight ahead (i.e. turns on intersections are forbidden).
Recent technical and magical advancements allowed R'Lyeh engineers to create a new class of vehicles, capable of turning either right or left. After providing all citizens with new vehicles, it became possible to convert some intersections into turn pairs (see picture) to further simplify the life in R'Lyeh. THe conversion must preserve the direction of traffic on each road segment.
The One Who Dreams in the Deep calls for your help. You must plan how to convert a maximum possible number of intersections into turn pairs, without breaking RRR connectedness.
First line of the input file contains integers W H. Following H lines contain W symbols each and represent a map of R'Lyeh Ring Road.
Used symbols are: '│' (ASCII 179), '─' (ASCII 196), '┌' (ASCII 218), '└' (ASCII 192), '┘' (ASCII 217), '┐' (ASCII 191), '┼' (ASCII 197, represents intersection), ' ' (ASCII 32).
NOTE: the input files are in DOS (aka CPP866) encoding. Copying samples from the problem text will not work unless you convert the encoding. You can download actual input files for the samples here: Sample 1 Sample 2.
It is guaranteed that somewhere on the map there exists an area of business and cultural center, which is always seen by the right hand when moving along the RRR.
First line of output file should contain an integer K — maximal number of crossings that can be converted into turn pairs.
Following K lines should contain a sequence of integer pairs, separated by spaces — coordinates of these crossings. Each pair consist of row and column numbers of input matrix respectively. Numeration starts from 0, so upper-left corner of input matrix has coordinates 0 0.
2 ≤ W, H ≤ 20
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | A. Zhuplev, A. Klenin | |||
Input file: | input.txt | Time limit: | 1 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
Underwater arithmetic is very elementary. There are just two operations: WITH and WITHOUT which mean addition and subtraction respectively.
Underwater mathematicians did not yet invent brackets, so all expressions are calculated from right to left. For example, the expression 3 WITH 5 WITHOUT 4 WITHOUT 7 is calculated as (3 + (5 − (4 − 7))).
Scientists of Nearsea Institute of Underwater Arithmetic need a program to evaluate such expressions.
First line of input file contains a single integer N. Following 2 × N + 1 lines describe the expression. Odd lines contain integer operands, even lines contain operations.
Output file must contain a single integer — calculation result.
1 ≤ N ≤ 103
All operands are in range from 0 to 103.
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | I. Tufanov | |||
Input file: | input.txt | Time limit: | 1 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
The Force can have a strong influence on the weak-minded.
Engineers of Nearsea Laboratory of Swimming developed brand new underwater vehicle. To receive additional funding, they were advised to name it "nano-vehicle".
After some thought about how to justify such a name, young engineer Vasya suggested to start measuring the force of vehicle thrusters in nano-newtons.
The proposal was cheerfully accepted, and you were asked to write a thruster control program for this vehicle.
The vehicle has four thrusters located on its left, right, up and down sides. Their thrust forces are denoted by integer values fL, fR, fU and fD accordingly. Valid values of these forces are integers in the range from −108 to 108 nano-newtons. Positive values mean forward thrust, negative values — backward thrust.
Although all thrusters are parallel to each other, they still can be used to rotate the vehicle. For example, if fL = −108, fR = 108, fU = fD = 0, then the vehicle turns left. If fL = fR = fU = fD = 108, then the vehicle goes forward at full speed.
For the human controller, instead of directly setting each thrust force, it is easier to specify total thrust T, horizontal torque H and vertical torque V, which are defined as follows:
Your program must, given the values of T, H and V, calculate valid values of fL, fR, fU and fD.
Input file contains three integers T H V.
Output file must contain four integers (valid thrusts) fL fR fU fD. If there are several solutions, output any of them. It is guaranteed that at least one solution exists.
−4*108≤ T ≤ 4*108;
−2*108≤ H, V ≤ 2*108;
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | I. Tufanov | |||
Input file: | input.txt | Time limit: | 3 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
Multi-vehicle cooperation is a hot topic in contemporary underwater robotics. Often a group of vehicles can finish the mission faster than just one. But you have to implement sophisticated control techniques to benefit from the cooperation.
Consider N vehicles and M tasks they should accomplish. Each task should be accomplished by exactly one vehicle. Each task is a track that a vehicle should follow. The task number i is defined by two edge points ai and bi, and length di (di ≥ |ai − bi|).
Vehicle is allowed to follow a track in any direction — either from ai to bi or from bi to ai. In both cases the length of the path will be di.
A plan is a sequence of tasks for each vehicle in order of execution. Every task in the plan is followed either in direct order (a to b) or in reverse order (from b to a). Each task should appear exactly once in the whole plan.
The j-th vehicle has a starting point sj. Vehicle executes its tasks according to its part of a plan. When a vehicle accomplishes one task, it goes to the start point of the next one, moving along the straight line. When all tasks assigned to a vehicle are done, it stops. Vehicle path length is a total path traveled by the vehicle during the plan execution. Plan length is a maximal vehicle path length of all vehicles in the plan.
Your program must, given vehicles and tasks, find a plan of minimal length.
Assume that vehicles operate on a plane (plane of constant depth) and that the vehicle size may be ignored.
Each point in the input file is described with two integers — its x and y coordinates.
On the first line of input file there are integers N M. Following N lines describe starting points si.
Next M lines describe tasks, each task descriptions consisting of points ai, bi and path length di.
Output file must describe a plan of minimal length. If there several such plans, output any of them.
Plan description consists of N blocks, each describes a sequence of tasks for one vehicle. j−th block starts with non-negative integer numj, followed by numj pairs (tjk, dirjk). Here tjk denotes a number of k-th task for j-th vehicle, it is an integer in range 1..M. The dirjk is either 0 or 1: 0 stands for passing tjk from a to b, 1 stands for passing tjk from b to a.
1 ≤ N, M≤ 10; 0 ≤ di ≤ 104;
All coordinates are integers in range 0..103.
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
Author: | A. Klenin | |||
Input file: | input.txt | Time limit: | 3 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
The main hall of the Nearsea Institute of Unspecified Underwater Studies has a shape of a long corridor. Along the corridor, there are N aquariums exhibiting various sea creatures. Aquariums are located at distances x1, …, xN from the hall entrance (xi < xi + 1).
The institute has recently got a new director, who decided that the aquarium maintenance is too costly, and issued an order to remove M (0 ≤ M ≤ N − 2) aquariums.
To minimize the disruption to the looks of the hall, it was decided that:
Your program must select aquariums for removal in such a way that the above conditions are satisfied.
Input file contains integers N M followed by N integers xi.
Output file should contain a single integer — the smallest possible maximum distance.
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | I. Tufanov | |||
Input file: | input.txt | Time limit: | 1 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
Scientists of Nearsea Institute of Linguistic Ichthyology study the fish language. They found few specific sounds which some fishes can emit, and assign letters of Latin alphabet to them. Then they took an underwater sound record and used state-of-the-art pattern recognition software to convert it into a string of letters.
They hypothesize that one sub-string of letters may have particular meaning in the fish language (sand so serve as a kind of "word"), and so they want to calculate how often that sub-string may have been used during the record.
You program must, given the strings T and W, find minimum and maximum number of non-overlapping occurrences of W in T.
For example, if W="abab" and T="ababbbabababab", the string may be interpreted as "(abab)bb(abab)(abab)" (giving 3 occurrences) or as "(abab)bbab(abab)ab" (giving 2 occurrences). So, the minimal number is 2 and the maximum is 3.
First line of input file contains string W. Second line of input file contains string T.
Output file should contain two integers — minimum and maximum number of non-overlapping occurrences of W in T.
1 ≤ length(W) ≤ 100;
1 ≤ length(T) ≤ 1000;
W and T contain small Latin letters only.
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | A. Zhuplev, A. Klenin | |||
Input file: | input.txt | Time limit: | 1 sec | |
Output file: | output.txt | Memory limit: | 256 Mb |
Recently, explorers have discovered a new species of giant sentient squids living at the bottom of a deep lake.
Squids are generally uninterested in dealing with humans. However, they showed appreciation for various jewels, especially diamonds, which are hard to find under water. In exchange, squids offered a wide selection of high-quality pearls.
So the trade was established. Each day, N different kinds of jewels were traded, some from the surface into the water, and some out of the water to the surface.
The Squid State Trading Commission established following rules:
You program must find the volume of the container for each kind of jewel, so as to satisfy commission's requirements.
Input file contains an integer N followed by N integers ai, where ai > 0 means that ai jewels of i-th kind are moved from the surface to the lake, and ai < 0 means that |ai| jewels of i-th kind are moved from the lake to the surface.
Output file must contain N integers bi (1 ≤ bi ≤ 1012), indicating the volume of containers for each kind of jewel. If there are several acceptable solutions, output any of them.
2 ≤ N ≤ 105
1 ≤ |ai| ≤ 105
2 × min(pos, neg) ≥ max(pos, neg), where pos is the number of positive values among ai and neg is the number of negative values.
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|