benchmarks.wiki / Public workspace

Humanity's Last Code Exam / 2019_A / Azulejos

Problem

Answer published by the source. Consult the official source to check your work against its answer.

platform

atcoder

question content

**Problem Description:** Ceramic artists Maria and João are opening a small azulejo store in Porto. Azulejos are the beautiful ceramic tiles for which Portugal is famous. Maria and João want to create an attractive window display, but, due to limited space in their shop, they must arrange their tile samples in two rows on a single shelf. Each of João’s tiles has exactly one of Maria’s tiles in front of it and each of Maria’s tiles has exactly one of João’s tiles behind it. These hand-crafted tiles are of many different sizes, and it is important that each tile in the back row is taller than the tile in front of it so that both are visible to passers-by. For the convenience of shoppers, tiles in each row are arranged in non-decreasing order of price from left to right. Tiles of the same price may be arranged in any order subject to the visibility condition stated above. Your task is to find an ordering of the tiles in each row that satisfies these constraints, or determine that no such ordering exists. **Input:** The first line of input contains an integer n n (1n5×105 1 \leq n \leq 5 \times 10^5 ), the number of tiles in each row. The next four lines contain n n integers each; the first pair of lines represents the back row of tiles and the second pair of lines represents the front row. Tiles in each row are numbered from 1 to n n according to their ordering in the input. The first line in each pair contains n n integers p1,,pn p_1, \ldots, p_n (1pi109 1 \leq p_i \leq 10^9 for each i i ), where pi p_i is the price of tile number i i in that row. The second line in each pair contains n n integers h1,,hn h_1, \ldots, h_n (1hi109 1 \leq h_i \leq 10^9 for each i i ), where hi h_i is the height of tile number i i in that row. **Output:** If there is a valid ordering, output it as two lines of n n integers, each consisting of a permutation of the tile numbers from 1 to n n . The first line represents the ordering of the tiles in the back row and the second represents the ordering of the tiles in the front row. If more than one pair of permutations satisfies the constraints, any such pair will be accepted. If no ordering exists, output `impossible`. **Sample Input 1:**
Plain-text mathematical notation (without MathML)
**Problem Description:**

Ceramic artists Maria and João are opening a small azulejo store in Porto. Azulejos are the beautiful ceramic tiles for which Portugal is famous. Maria and João want to create an attractive window display, but, due to limited space in their shop, they must arrange their tile samples in two rows on a single shelf. Each of João’s tiles has exactly one of Maria’s tiles in front of it and each of Maria’s tiles has exactly one of João’s tiles behind it. These hand-crafted tiles are of many different sizes, and it is important that each tile in the back row is taller than the tile in front of it so that both are visible to passers-by. For the convenience of shoppers, tiles in each row are arranged in non-decreasing order of price from left to right. Tiles of the same price may be arranged in any order subject to the visibility condition stated above.

Your task is to find an ordering of the tiles in each row that satisfies these constraints, or determine that no such ordering exists.

**Input:**

The first line of input contains an integer n (1≤n≤5×10⁵), the number of tiles in each row. The next four lines contain n integers each; the first pair of lines represents the back row of tiles and the second pair of lines represents the front row. Tiles in each row are numbered from 1 to n according to their ordering in the input. The first line in each pair contains n integers p₁,…,p_(n) (1≤p_(i)≤10⁹ for each i), where p_(i) is the price of tile number i in that row. The second line in each pair contains n integers h₁,…,h_(n) (1≤h_(i)≤10⁹ for each i), where h_(i) is the height of tile number i in that row.

**Output:**

If there is a valid ordering, output it as two lines of n integers, each consisting of a permutation of the tile numbers from 1 to n. The first line represents the ordering of the tiles in the back row and the second represents the ordering of the tiles in the front row. If more than one pair of permutations satisfies the constraints, any such pair will be accepted. If no ordering exists, output `impossible`.

**Sample Input 1:**

Original LaTeX notation
**Problem Description:**

Ceramic artists Maria and João are opening a small azulejo store in Porto. Azulejos are the beautiful ceramic tiles for which Portugal is famous. Maria and João want to create an attractive window display, but, due to limited space in their shop, they must arrange their tile samples in two rows on a single shelf. Each of João’s tiles has exactly one of Maria’s tiles in front of it and each of Maria’s tiles has exactly one of João’s tiles behind it. These hand-crafted tiles are of many different sizes, and it is important that each tile in the back row is taller than the tile in front of it so that both are visible to passers-by. For the convenience of shoppers, tiles in each row are arranged in non-decreasing order of price from left to right. Tiles of the same price may be arranged in any order subject to the visibility condition stated above.

Your task is to find an ordering of the tiles in each row that satisfies these constraints, or determine that no such ordering exists.

**Input:**

The first line of input contains an integer \( n \) (\( 1 \leq n \leq 5 \times 10^5 \)), the number of tiles in each row. The next four lines contain \( n \) integers each; the first pair of lines represents the back row of tiles and the second pair of lines represents the front row. Tiles in each row are numbered from 1 to \( n \) according to their ordering in the input. The first line in each pair contains \( n \) integers \( p_1, \ldots, p_n \) (\( 1 \leq p_i \leq 10^9 \) for each \( i \)), where \( p_i \) is the price of tile number \( i \) in that row. The second line in each pair contains \( n \) integers \( h_1, \ldots, h_n \) (\( 1 \leq h_i \leq 10^9 \) for each \( i \)), where \( h_i \) is the height of tile number \( i \) in that row.

**Output:**

If there is a valid ordering, output it as two lines of \( n \) integers, each consisting of a permutation of the tile numbers from 1 to \( n \). The first line represents the ordering of the tiles in the back row and the second represents the ordering of the tiles in the front row. If more than one pair of permutations satisfies the constraints, any such pair will be accepted. If no ordering exists, output `impossible`.

**Sample Input 1:**

Code

4
3 2 1 2
2 3 4 3
2 1 2 1
2 2 1 3

**Sample Output 1:**

Code

3 2 4 1
4 2 1 3

**Sample Input 2:**

Code

2
1 2
2 3
2 8
2 1

**Sample Output 2:**

Code

impossible

question title

Azulejos

Discussion

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

Official source

initial import