RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00536

Slagalica

Unrated 레이팅 미적용
난이도
1s
시간 제한
512MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Little Fabian got a o\(ne-di\)mensional jigsaw puzzle that consists of \(N\) pieces. He quickly realized that each
piece belongs to one of the following types:
Additionally, it is known that among those \(N\) pieces there is exactly one piece of either type 5 or type 6
(left border) and exactly one piece of either type 7 or type 8 (right border).
Fabian wishes to arrange all of the pieces into a single row such that the first (leftmost) piece is of type 5
or 6 and the last (rightmost) piece is of type 7 or 8. Two pieces can be placed next to each other if and
only if their neighbouring borders are of different shapes, i.e., one has a bump (also called outie or tab)
and the other has a hole (also called innie or blank).
Simply solving the puzzle would be too easy for Fabian so he decided to write a unique positive integer on
each of the pieces. Now he is interested in finding the lexicographically smallest solution to the jigsaw
puzzle. The solution \(A\) is considered lexicographically smaller than solution \(B\) if at the first position
(from the left) \(i\) where they differ it holds that the number written on \(i-th\) puzzle in \(A\) is smaller than the
number written on \(i-th\) puzzle in \(B\).
Note: the pieces cannot be rotated.

제약

In test cases worth a total of 5 points it will hold \(N \le 4\).
In test cases worth additional 5 points it will hold \(N \le 10\).
In test cases worth additional 10 points pieces of types 2 and 3 will not appear in the input.
In test cases worth additional 20 points there will be at most one piece of type 1 or 4.
If for some test case in which the solution to the puzzle exists, you output the correctly solved puzzle but
your solution is not lexicographically smallest, you will get 40% of the points intended for that test case.

입력 형식

The first line contains an integer \(N\) (\(2 \le N \le 10^{5}\)) from the task description.
The next \(N\) lines contain two integers \(X@@RISE_MATH_BLOCK_0@@i \le 8\)) and \(A@@RISE_MATH_BLOCK_1@@i \le 10^{9}\)) which represent the type
of the \(i-th\) piece and the number Fabian wrote on it. All numbers \(A\)\(i\) will be different.

출력 형식

If Fabian cannot solve the jigsaw puzzle, you should outp\(ut - 1\) in a single line.
Otherwise, you should output the numbers that are written on the pieces in the lexicographically smallest
solution to the puzzle.

예제 1
입력
5
1 5
2 7
2 3
8 4
6 1
출력
1 3 7 5 4
예제 2
입력
3
5 1
7 2
4 3
출력
1 3 2
예제 3
입력
5
2 5
2 7
2 3
8 4
6 1
출력
-1
설명

Clarification of the first example:
There are only two possible solutions to the puzzle:
We can see that the second depicted solution has a smaller number written on the second piece. Therefore,
that is the lexicographically smallest solution.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2019/2020 Contest 2

평가 및 의견

Slagalica

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Slagalica

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8