benchmarks.wiki / Public workspace
Humanity's Last Code Exam / 2017_L / Visual Python++
Problem
Answer published by the source. Consult the official source to check your work against its answer.
question title
Visual Python++
question content
## Problem Description
In the recently proposed Visual Python++ programming language, a block of statements is represented as a rectangle of characters with top-left corner in row and column , and bottom-right corner in row and column . All characters at locations with and are then considered to belong to that block. Among these locations, the ones with or or or are called a border.
Statement blocks can be nested (rectangles contained in other rectangles) to an arbitrary level. In a syntactically correct program, every two statement blocks are either nested (one contained in the other) or disjoint (not overlapping). In both cases, their borders may not overlap.
Programmers are not expected to draw the many rectangles contained in a typical program – this takes too long, and Visual Python++ would not have a chance to become the next ICPC programming language. So a programmer only has to put one character ‘p’ in the top-left corner of the rectangle and one character ‘y’ in the bottom-right corner. The parser will automatically match up the appropriate corners to obtain the nesting structure of the program.
Your team has just been awarded a five-hour contract to develop this part of the parser.
## Input
The first line of the input contains an integer , the number of corner pairs. Each of the next lines contains two integers and , specifying that there is a top-left corner in row and column of the program you are parsing. Following that are lines specifying the bottom-right corners in the same way. All corner locations are distinct.
## Output
Display lines, each containing one integer. A number in line means that the -th top-left corner and the -th bottom-right corner form one rectangle. Top-left and bottom-right corners are each numbered from 1 to in the order they appear in the input. The output must be a permutation of the numbers from 1 to such that the matching results in properly nested rectangles. If there is more than one valid matching, any one will be accepted. If no such matching exists, display `syntax error`.
## Sample Input 1
Plain-text mathematical notation (without MathML)
## Problem Description In the recently proposed Visual Python++ programming language, a block of statements is represented as a rectangle of characters with top-left corner in row r₁ and column c₁, and bottom-right corner in row r₂ and column c₂. All characters at locations (r,c) with r₁≤r≤r₂ and c₁≤c≤c₂ are then considered to belong to that block. Among these locations, the ones with r=r₁ or r=r₂ or c=c₁ or c=c₂ are called a border. Statement blocks can be nested (rectangles contained in other rectangles) to an arbitrary level. In a syntactically correct program, every two statement blocks are either nested (one contained in the other) or disjoint (not overlapping). In both cases, their borders may not overlap. Programmers are not expected to draw the many rectangles contained in a typical program – this takes too long, and Visual Python++ would not have a chance to become the next ICPC programming language. So a programmer only has to put one character ‘p’ in the top-left corner of the rectangle and one character ‘y’ in the bottom-right corner. The parser will automatically match up the appropriate corners to obtain the nesting structure of the program. Your team has just been awarded a five-hour contract to develop this part of the parser. ## Input The first line of the input contains an integer n (1≤n≤10⁵), the number of corner pairs. Each of the next n lines contains two integers r and c (1≤r,c≤10⁹), specifying that there is a top-left corner in row r and column c of the program you are parsing. Following that are n lines specifying the bottom-right corners in the same way. All corner locations are distinct. ## Output Display n lines, each containing one integer. A number j in line i means that the i-th top-left corner and the j-th bottom-right corner form one rectangle. Top-left and bottom-right corners are each numbered from 1 to n in the order they appear in the input. The output must be a permutation of the numbers from 1 to n such that the matching results in properly nested rectangles. If there is more than one valid matching, any one will be accepted. If no such matching exists, display `syntax error`. ## Sample Input 1
Original LaTeX notation
## Problem Description In the recently proposed Visual Python++ programming language, a block of statements is represented as a rectangle of characters with top-left corner in row \(r_1\) and column \(c_1\), and bottom-right corner in row \(r_2\) and column \(c_2\). All characters at locations \((r, c)\) with \(r_1 \leq r \leq r_2\) and \(c_1 \leq c \leq c_2\) are then considered to belong to that block. Among these locations, the ones with \(r = r_1\) or \(r = r_2\) or \(c = c_1\) or \(c = c_2\) are called a border. Statement blocks can be nested (rectangles contained in other rectangles) to an arbitrary level. In a syntactically correct program, every two statement blocks are either nested (one contained in the other) or disjoint (not overlapping). In both cases, their borders may not overlap. Programmers are not expected to draw the many rectangles contained in a typical program – this takes too long, and Visual Python++ would not have a chance to become the next ICPC programming language. So a programmer only has to put one character ‘p’ in the top-left corner of the rectangle and one character ‘y’ in the bottom-right corner. The parser will automatically match up the appropriate corners to obtain the nesting structure of the program. Your team has just been awarded a five-hour contract to develop this part of the parser. ## Input The first line of the input contains an integer \(n\) \((1 \leq n \leq 10^5)\), the number of corner pairs. Each of the next \(n\) lines contains two integers \(r\) and \(c\) \((1 \leq r, c \leq 10^9)\), specifying that there is a top-left corner in row \(r\) and column \(c\) of the program you are parsing. Following that are \(n\) lines specifying the bottom-right corners in the same way. All corner locations are distinct. ## Output Display \(n\) lines, each containing one integer. A number \(j\) in line \(i\) means that the \(i\)-th top-left corner and the \(j\)-th bottom-right corner form one rectangle. Top-left and bottom-right corners are each numbered from 1 to \(n\) in the order they appear in the input. The output must be a permutation of the numbers from 1 to \(n\) such that the matching results in properly nested rectangles. If there is more than one valid matching, any one will be accepted. If no such matching exists, display `syntax error`. ## Sample Input 1
Code
2
4 7
9 8
14 17
19 18
## Sample Output 1
Code
2
1
## Sample Input 2
Code
2
4 7
14 17
9 8
19 18
## Sample Output 2
Code
1
2
## Sample Input 3
Code
2
4 8
9 7
14 18
19 17
## Sample Output 3
Code
syntax error
## Sample Input 4
Code
3
1 1
4 8
8 4
10 6
6 10
10 10
## Sample Output 4
Code
syntax error
platform
atcoder
Discussion
No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.
Source and history
initial import