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 i-th position, providing that the second string has a blue bead in the i-th position, and the first two beads i - 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 k.

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)。他知道玛莎只喜欢两种颜色:蓝色和红色;而他所到的这家商店里,恰好有大量由这两种颜色珠子串成的饰品。所有珠串都配有小型搭扣;若将搭扣解开,便会发现商店中所有珠串长度均相同。由于火星人视觉的特殊性,若佐格先看到一条蓝红相间的珠串,再看到另一条将其中蓝色珠子全部替换为红色、红色珠子全部替换为蓝色所得的珠串,则他会认为这两条珠串完全相同。换言之,佐格不仅将可通过翻转(即字符串反转)相互得到的珠串视为相同,还将可通过颜色互换(即 0↔1 替换)和/或翻转相互得到的珠串也视为相同。

众所周知,所有火星人都极其讲究秩序:当一个火星人面对若干对象时,总会尝试将其有序排列。佐格认为红色珠子比蓝色珠子“小”;我们用 0 表示红色珠子,1 表示蓝色珠子。对于两条珠串,若它们前 i1i-1 位完全相同,而第 ii 位上第一条珠串为红色(即 0),第二条为蓝色(即 1),则火星人会将第一条珠串排在第二条之前。

佐格首先解开所有珠串的搭扣,并将它们分堆存放,使得每堆内的珠串在他看来均彼此相同。接着,他对每一堆进行排序,并选出该堆中在他看来最小的那条珠串。他将其余不必要的珠串退还给店员,声称自己不再需要它们。最后,佐格对剩余的珠串再次排序,并购买序号为 kk 的那条珠串。

这些操作将耗费佐格大量时间,因此他请你帮忙,找出最终送给玛莎的那条珠串。

输入格式

The input file contains two integers n and k (2 ≤ n ≤ 50;1 ≤ k ≤ 1016) —the length of a string of beads, and the index of the string, chosen by Zorg.

输入文件包含两个整数 nnkk2n502 \leq n \leq 501k10161 \leq k \leq 10^{16})——分别为珠串的长度,以及佐格所选定的珠串的序号。

输出格式

Output the k-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.

输出第 k 个珠子串,用 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.

我们以长度为 4 的字符串为例——0001、0010、0011、0100、0101、0110、0111、1000、1001、1010、1011、1100、1101、1110。佐格将它们划分为若干堆:{0001, 0111, 1000, 1110}、{0010, 0100, 1011, 1101}、{0011, 1100}、{0101, 1010}、{0110, 1001}。然后,他在每堆中选出字典序最小的字符串:0001、0010、0011、0101、0110。第四个字符串是——0101。

输入解题思路,AI测评打分。不知道怎么写?

首页