CF8E.Beads

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if one unfastens it, one might notice that all the strings of beads in the shop are of the same length. Because of the peculiarities of the Martian eyesight, if Zorg sees one blue-and-red string of beads first, and then the other with red beads instead of blue ones, and blue — instead of red, he regards these two strings of beads as identical. In other words, Zorg regards as identical not only those strings of beads that can be derived from each other by the string turnover, but as well those that can be derived from each other by a mutual replacement of colours and/or by the string turnover.

It is known that all Martians are very orderly, and if a Martian sees some amount of objects, he tries to put them in good order. Zorg thinks that a red bead is smaller than a blue one. Let's put 0 for a red bead, and 1 — for a blue one. From two strings the Martian puts earlier the string with a red bead in the ii -th position, providing that the second string has a blue bead in the ii -th position, and the first two beads i1i-1 are identical.

At first Zorg unfastens all the strings of beads, and puts them into small heaps so, that in each heap strings are identical, in his opinion. Then he sorts out the heaps and chooses the minimum string in each heap, in his opinion. He gives the unnecassary strings back to the shop assistant and says he doesn't need them any more. Then Zorg sorts out the remaining strings of beads and buys the string with index kk .

All these manupulations will take Zorg a lot of time, that's why he asks you to help and find the string of beads for Masha.

彩色珠子

火星人Zorg想要送一串珠子给他来自地球的朋友Masha。他知道Masha喜欢蓝色和红色两种颜色。他来到的商店里有各种颜色的珠子。所有的珠子串都有一个小的扣子,如果解开它,就会发现商店里所有的珠子串长度都是相同的。

由于火星人的视力特殊,如果Zorg先看到一串蓝红相间的珠子,然后看到另一串以红珠子代替蓝珠子、以蓝珠子代替红珠子的珠子,他会认为这两串珠子是相同的。换句话说,Zorg认为那些可以通过串的翻转得到的珠串是相同的,同样那些可以通过颜色的互换和/或串的翻转得到的珠串也是相同的。众所周知,所有的火星人都非常有秩序感,如果火星人看到一些物体,他们会试图把它们整齐地摆放。

Zorg 认为红色珠子比蓝色珠子小。我们将红色珠子表示为 0,蓝色珠子表示为 1。对于两个珠子串,如果第二个串在第 ii 个位置有一个蓝色珠子,而第一个串的前 i1i-1 个珠子完全相同,则火星人会优先选择第一个串。

首先,Zorg解开所有的珠子串,然后将它们分成小堆,使得每个堆中的珠子串在他看来是相同的。然后,他对堆进行排序,并选择每个堆中的最小珠子串。他将不需要的珠子串退还给店员,并告诉他不再需要它们。然后,Zorg对剩下的珠子串进行排序,并购买第 kk 个珠子串。
由于所有这些操作都会花费Zorg很多时间,所以他请求你的帮助,为Masha找到珠子串。

感谢Macw提供翻译

输入格式

The input file contains two integers nn and kk ( 2<=n<=50;1<=k<=10162<=n<=50;1<=k<=10^{16} ) —the length of a string of beads, and the index of the string, chosen by Zorg.

输入包含一行。
输入nnkk两个整数(2n50;1k1016)(2 ≤ n ≤ 50; 1 ≤ k ≤ 10^{16}),表示珠串的长度和Zorg选择的字符串的索引。

输出格式

Output the kk -th string of beads, putting 0 for a red bead, and 1 — for a blue one. If it s impossible to find the required string, output the only number -1.

输出第kk个珠串,红色珠子表示为0,蓝色珠子表示为 1。如果无法找到所需的字符串,则输出唯一的数字-1

输入输出样例

  • 输入#1

    4 4
    

    输出#1

    0101
    

说明/提示

Let's consider the example of strings of length 4 — 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110. Zorg will divide them into heaps: {0001, 0111, 1000, 1110}, {0010, 0100, 1011, 1101}, {0011, 1100}, {0101, 1010}, {0110, 1001}. Then he will choose the minimum strings of beads in each heap: 0001, 0010, 0011, 0101, 0110. The forth string — 0101.

请注意,本题的时间限制为5s,是默认时间限制的五倍。空间限制为64MB,是默认空间限制的二分之一。

首页