CF8E.Beads
省选/NOI-
通过率:0%
时间限制:5.00s
内存限制:64MB
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 表示蓝色珠子。对于两个字符串,若在第 i 位上,第一个字符串为红色珠子(即 0),而第二个字符串为蓝色珠子(即 1),且前 i−1 位完全相同,则火星人会将第一个字符串排在第二个字符串之前。
佐格首先解开所有珠子串的搭扣,并将它们分堆存放,使得每堆内所有珠子串在他看来都是“相同的”。接着,他对每一堆进行排序,并从中选出他认为“最小”的那一串(即字典序最小的串)。他将堆中其余“非最小”的串退还给店员,声称自己不再需要它们。最后,佐格对所有剩余的珠子串再次排序,并购买其中索引为 k 的那一串(索引从 1 开始计数)。
完成上述所有操作将耗费佐格大量时间,因此他请你帮忙,找出最终他要买给玛莎的那串珠子。
输入格式
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.
输入文件包含两个整数 n 和 k(2 ≤ n ≤ 50;1 ≤ k ≤ 1016)——分别为珠串的长度,以及佐格所选定的珠串的序号。
输出格式
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测评打分。不知道怎么写?