IOI '97 - Cape Town, South Africa
You are a cartographer's assistant, and have been given the difficult task of writing the names of cities onto a new map.
The map is a grid of cells. Grid cells coordinates are labelled from to inclusive in the horizontal and vertical direction respectively. Each city occupies a single cell on the map. City names are to be placed on the map in rectangular boxes of cells. Such boxes are called labels.
Figure 1: a city with the four possible positions of its label
The placement of labels must satisfy the following constraints:
- A city's label must appear in one of four positions with respect to the city as illustrated in figure .
- Labels must not overlap each other.
- Labels must not overlap cities.
- Labels must completely fit on the map.
Each label contains all the letters in a city name plus a single space. For each city name the width and height of its letters will be given; the single space has the same size.
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | _ | C | e | r | e | s | ||||||||||
1 | O | P | a | a | r | l | _ | |||||||||
2 | ||||||||||||||||
3 | O | O | ||||||||||||||
4 | L | a | n | g | a | _ | ||||||||||
_ represents a spaceO represents the position of a city |
The leftmost column of the map has horizontal index 0 and the top row has vertical index . Figure shows the top left section of a map for the cities Langa at , Ceres at and Paarl at . All the labels are validly placed, but this is not the only valid placement.
Your program must read the locations of the cities on the map, followed by their letter dimensions and names. The program must then place as many labels on the map as it can without violating the constraints above, and output the locations of the labels that have been placed.
Input Specification
The input starts with a line containing an integer giving the number of cities on the map. For each city there is an input line with
- the city's horizontal index ,
- the city's vertical index ,
- the integer width for each character of the city name,
- the integer height for each character of the city name, and
- the city name itself, which consists only of uppercase and lowercase characters from
A
toZ
.
City names are all single words. The number of cities is at most . No city name will be longer than letters.
Output Specification
Your program must output lines. Each line must contain the
horizontal index followed by the vertical index of the top left cell of
the city's label, separated by a single space. If your program is unable
to place a label for a city, it must output -1 -1
for that city. These lines should be printed in the same order as the
cities are given in the input.
Sample Input
Input | Explanation |
---|---|
|
|
Sample Output
Output | Explanation |
---|---|
|
|
Scoring
For each test case:
- Your score will be given as the percentage of city names placed by your program with respect to an excellent solution of the IOI organisers, rounded to the nearest integer percent.
- The minimum score is and the maximum score is .
- If any label violates the constraints, your program will score .
- If labels do not match the cities given, your program will score .
Comments