CF120I.Luck is in Numbers

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vasya has been collecting transport tickets for quite a while now. His collection contains several thousands of tram, trolleybus and bus tickets. Vasya is already fed up with the traditional definition of what a lucky ticket is. Thus, he's looking for new perspectives on that. Besides, Vasya cannot understand why all tickets are only divided into lucky and unlucky ones. He thinks that all tickets are lucky but in different degrees. Having given the matter some thought, Vasya worked out the definition of a ticket's degree of luckiness. Let a ticket consist of 2_n_ digits. Let's regard each digit as written as is shown on the picture:

You have seen such digits on electronic clocks: seven segments are used to show digits. Each segment can either be colored or not. The colored segments form a digit. Vasya regards the digits as written in this very way and takes the right half of the ticket and puts it one the left one, so that the first digit coincides with the n + 1-th one, the second digit coincides with the n + 2-th one, ..., the n-th digit coincides with the 2_n_-th one. For each pair of digits, put one on another, he counts the number of segments colored in both digits and summarizes the resulting numbers. The resulting value is called the degree of luckiness of a ticket. For example, the degree of luckiness of ticket 03 equals four and the degree of luckiness of ticket 2345 equals six.

You are given the number of a ticket containing 2_n_ digits. Your task is to find among the tickets whose number exceeds the number of this ticket but also consists of 2_n_ digits such ticket, whose degree of luckiness exceeds the degrees of luckiness of the given ticket. Moreover, if there are several such tickets, you should only choose the one with the smallest number.

瓦西娅收集交通车票已经有一段时间了。他的收藏中包含了数千张有轨电车、无轨电车和公共汽车的车票。瓦西娅早已厌倦了传统意义上“幸运车票”的定义,因此他正在寻求新的视角。此外,瓦西娅无法理解为什么所有车票仅被划分为“幸运”与“不幸运”两类;他认为所有车票都是幸运的,只是幸运程度不同而已。经过一番思考,瓦西娅提出了车票“幸运度”的定义。

设一张车票由 2n2n 位数字组成。我们把每一位数字视为如下图所示的形式书写:

你曾在电子钟表上见过这类数字:使用七段数码管显示数字,每一段可以点亮(着色)或不点亮(未着色),点亮的段组合起来便构成一个数字。瓦西娅正是按这种七段数码管方式来理解各位数字,并将车票的右半部分(即后 nn 位)叠放在左半部分(即前 nn 位)之上,使得第 11 位与第 n+1n+1 位对齐、第 22 位与第 n+2n+2 位对齐、……、第 nn 位与第 2n2n 位对齐。对于每一对重叠的数字(即第 ii 位与第 n+in+i 位,其中 1≤i≤n1 \le i \le n),他统计两个数字中同时点亮的段的数量,并将这 nn 对数字所得的计数结果相加。该总和即为这张车票的幸运度。

例如,车票 03 的幸运度为 44,而车票 2345 的幸运度为 66。

现给出一张含 2n2n 位数字的车票编号。你的任务是:在所有编号严格大于给定车票编号、且同样由 2n2n 位数字组成的车票中,找出幸运度严格大于给定车票幸运度的车票;若存在多个满足条件的车票,则选择其中编号最小的一张。

输入格式

The first line contains the number of the ticket that consists of k characters (k = 2_n_, 1 ≤ n ≤ 105).

第一行包含一张由 kk 个字符组成的车票号码(k=2nk = 2n,其中 1≤n≤1051 \leq n \leq 10^5)。

输出格式

Print the number of the sought ticket or "-1" (without the quotes) if no such ticket exists.

输出所求车票的编号,如果不存在这样的车票,则输出 “-1”(不带引号)。

输入输出样例

  • 输入#1

    13

    输出#1

    20
  • 输入#2

    2345

    输出#2

    2348
  • 输入#3

    88

    输出#3

    -1

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

首页