De Bruijn sequences (2) P55027


Statement
 

pdf   zip

As you may remember, a binary de Bruijn sequence of order nn is a cyclic sequence of zeros and ones such that every possible subsequence of nn consecutive digits appears exactly once.

Regarding the problem about de Bruijn sequences of the last UPC semifinal, Masao did not like that some precomputed solutions were accepted. In the good old days, when men were real men, and Masao was a UPC world-finalist of the ACM contest (and a real man, like now), things were not so easy! Therefore, let us make that problem a little tougher.

Input

Input consists of several cases. Every case begins with an integer number nn, followed by a number rr, followed by rr restrictions, each consisting of a pair of integer numbers ii and vv, which state that the ii-th leftmost position of the sequence must be vv. Assume 2n202 \le n \le 20, 0i<2n0 \le i < 2^n and v{0,1}v \in \{0, 1\}. The positions are all different.

Output

For every case, print the lexicographically smallest de Bruijn sequence of order nn that fulfills all the restrictions. If such a sequence does not exists, state so as shown in the sample output.

Observation

The private test cases are chosen so that a “reasonable” brute-force algorithm should be accepted, if written non-recursively.

Public test cases
  • Input

    3 0
    3 1    0 1
    2 2    0 1  2 1
    4 5    3 1  11 0  9 1  15 0  6 0
    

    Output

    00010111
    10001011
    no solution
    0011010111100100
    
  • Information
    Author
    Xavier Martínez
    Language
    English
    Official solutions
    C++
    User solutions
    C++