Joy With Cookies

시간 제한2초메모리 제한512 MB

요약
쌓인 직사각형보다 가로와 세로가 모두 짧아야 올릴 수 있는 게임에서, 주어진 k개의 쿠키 방향을 정해 선공이 이기도록 만드는 배치를 찾는다.
난이도

보통10점 중 7점

유형
게임 이론, 그리디, 정렬
정답자
아직 제출이 없습니다

문제

Joseph and Carl are playing the next funny game. There are nn different types of rectangular cookies, each cookie have side XX and YY of length x_ix\_i and y_iy\_i respectively. Both players have access to infinite number of each cookie.

The game consists of two stages: setup and play. At the first stage, Joseph sets up the playfield.

  • He choose exactly kk cookies and puts them on the plane such as sides of each cookie are parallel to the coordinate axis and no two cookies share a common point. 
  • During the setup stage (and only then), Joseph can freely choose orientation of any of placed cookies: place the side XX horizontally or or rotate the cookie by 90 degrees.
  • At the end of the stage, each the chosen kk cookies becomes the bottom for the some stack, so play stage starts with kk empty stacks,.

AFter the setup stage, the play starts. The players put cookies in turns, Carl starts first.  For one turn player chooses a cookie and puts it in  some stack at the top. The following requirements must be held:

  • The side XX of the cookie at this stage of game must be horizontal. 
  • The cookie AA can be placed to the top of stack bb,  if vertical side of AA is strictly shorter than vertical side of the cookie from the top, and horizontal side of AA is strictly shorter than horizontal side of the cookie from the top.

The player, who cannot do the correct move at his turn, lose.

You know the cookies that were chosen by Joseph. Your task is to find one of possible initial rotations of cookies which ensure that Joseph at the play stage wins when both players playing optimally, or tell that it is impossible for Joseph to win regardless of his decisions about starting cookies' orientation.

입력

The first line of the input contains two integers nn and kk (1≤n,k≤1051 \le n, k \le 10^5) --- number of cookie types and number of cookies used by Joseph at the setup stage.

ii-th of the following nn lines contain two numbers x_ix\_i and y_iy\_i (1≤x_i,y_i≤1051 \le x\_i, y\_i \le 10^5) --- lengths of xx-parallel and yy-parallel sides of the ii-th cookie type. You may assume that no two cookie types same x_ix\_i size and no two cookie types have same y_iy\_i size.

The last line of the input contains kk integers a_ia\_i (1≤a_i≤n1 \le a\_i \le n) --- cookie types used by Joseph while setting the game up.

출력

If it is impossible for Joseph to put the chosen kk cookies to ensure victory, print "impossible". Otherwise print one binary string of length kk. The ii-th from the left bit is equal to 0, the ii-th cookie in order they are listed in the input is not rotated (i.e. x_ix\_i is horizontal), if it is equal to 1, cookie is rotated by 90 degrees and y_iy\_i is horizontal. IF there are more than one solution, you may print any of them.

예제2

  1. 예제 1

    입력
    5 3
    1 1
    4 5
    3 4
    5 3
    6 6
    1 2 4
    
    예상 출력
    010
    
  2. 예제 2

    입력
    5 3
    1 1
    3 4
    5 3
    4 5
    7 7
    5 1 2
    
    예상 출력
    impossible