Dramatic Duel
Time limit1sMemory limit512 MB
Given n carpet kinds and k stacked carpets, the task is to pick each carpet's orientation so the guide, who moves first, loses, or report that no such placement exists.
- Level
Hard8 of 10
- Topics
- Game theory, Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
Noon. A meadow stands in front of a photogenic building named after Heydar Aliyev. Mr. Malnar, the protagonist of this anecdote, orders his loyal squad of Olympians to flip over. At that moment, a brave gentleman hurries toward Mr. Malnar. He is the guide of the Croatian team and also the antagonist. Nobody knew that this was the start of an epic clash people would talk about for years.
To settle the clash, they agreed to play a game. Azerbaijan has kinds of rectangular carpets, and the -th kind has sides S and D of lengths and . Each player has an unlimited supply of carpets of every kind.
The game starts with Mr. Malnar placing exactly carpets on the ground, so that the -th carpet placed is of kind . For each carpet, Mr. Malnar chooses whether side S or side D is parallel to the equator.
The players take turns, starting with the guide. The player who cannot make a move loses. On a move, a player takes a fresh carpet of any kind and places it on top of one of the stacks on the ground. The carpet is placed with side S parallel to the equator, and it must lie completely on the carpet beneath it. In other words, when carpet is placed on carpet , the side of parallel to the equator must be strictly less than the side of parallel to the equator, and the side of perpendicular to the equator must be strictly less than the side of perpendicular to the equator.
Mr. Malnar played perfectly, and so did his opponent, to everyone's surprise. The records of the duel preserve the values and for every kind and the kinds of all carpets that were on the ground. The only unknown is how Mr. Malnar oriented the first carpets. Find one way to place the first carpets that guarantees him a win.
Input
The first line contains integers and ().
Each of the next lines contains two integers and (). No two carpets have the same width, and no two carpets have the same length.
The last line contains integers ().
Output
If Mr. Malnar cannot win no matter how he places the first carpets, print nemoguce on a single line. Otherwise, print a string of characters, each 0 or 1, on a single line. If the -th character is 1, Mr. Malnar placed the -th carpet with side D parallel to the equator. If it is 0, he placed it with side S parallel to the equator.