Max and Cards

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Max is a magician whose job is to shuffle magic cards and confuse innocent bystanders. He uses a special deck with N cards, labelled from 1 to N. Suddenly, he throws his hands up in the air and the cards fall back down in a sorted order (from least to greatest). He then quickly swipes his hands over the cards and forms all N! possible permutations from lexicographically least to greatest ordered from 0 to N!-1. For example, if N=3 then he would have made the permutations

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

Afterwards, Max asks you Q questions in the form of what was the Q_i^{th} permutation that Max made. Since your tiny eyes were too slow to see Max's amazing trick, you try using your old Pentium 4 computer to recreate Max's magic, but can you do it fast enough?

Input

The first line will contain N (3 \le N \le 19).
The second line will contain Q (3 \le Q \le 100).
The next Q lines will contain Q_i (0 \le Q_i < N!).

Output

For each question, output the Q_i^{th} permutation on its own line.

Scoring

At least 50% of the testcases will have N \le 10.

Sample Input

3
6
5
4
3
2
1
0

Sample Output

3 2 1
3 1 2
2 3 1
2 1 3
1 3 2
1 2 3

Comments


  • 2
    HowAboutNo  commented on Jan. 10, 2016, 4:55 p.m.

    Judge down right now and I have a solution for partial marks. What do?


    • 3
      Xyene  commented on Jan. 10, 2016, 5:03 p.m.

      A judge has been made available.


      • 2
        HowAboutNo  commented on Jan. 10, 2016, 5:39 p.m. edited

        Thanks! Couldn't implement the problem well enough, but extra points are extra points.

        Edit: The points are partial, but they aren't showing up under my score.


        • 3
          bobhob314  commented on Jan. 10, 2016, 5:48 p.m.

          Pretty sure it's fixed now.


      • 4
        bobhob314  commented on Jan. 10, 2016, 5:06 p.m.

        Could you give him an extra submission? I think his timer ran out before he could submit for partial.