CF1340B.Nastya and Scoreboard

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer.

The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of 77 segments, which can be turned on or off to display different numbers. The picture shows how all 1010 decimal digits are displayed:

After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly kk segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly kk sticks (which are off now)?

It is allowed that the number includes leading zeros.

丹尼斯在买了鲜花和糖果之后(这个故事将在下一题中讲述),便去和娜斯佳约会,向她求婚。此刻,他们正坐在咖啡馆里,终于……丹尼斯向她表白,希望两人成为情侣,但……娜斯佳却未作任何回应。

可怜的男孩因此非常沮丧。他悲伤至极,一拳砸向了一块显示数字的电子计分板。这些数字的显示方式与电子钟相同:每个数位由 77 个可独立点亮或熄灭的线段组成,从而显示不同的数字。下图展示了全部 1010 个十进制数字的显示方式:

这一拳导致部分线段损坏——即原本点亮的某些线段可能因此熄灭。但丹尼斯记得最初有多少根线段是点亮的,以及现在还有多少根线段仍在点亮。丹尼斯恰好打坏了 kk 根线段,且他知道当前哪些线段仍能正常工作。于是他提出了一个问题:如果恰好点亮 kk 根目前熄灭的线段(即“开启”这 kk 根线段),那么计分板上所能显示的最大可能数字是多少?

允许该数字包含前导零。

输入格式

The first line contains integer nn (1≤n≤2000)(1 \leq n \leq 2000) — the number of digits on scoreboard and kk (0≤k≤2000)(0 \leq k \leq 2000) — the number of segments that stopped working.

The next nn lines contain one binary string of length 77, the ii-th of which encodes the ii-th digit of the scoreboard.

Each digit on the scoreboard consists of 77 segments. We number them, as in the picture below, and let the ii-th place of the binary string be 00 if the ii-th stick is not glowing and 11 if it is glowing. Then a binary string of length 77 will specify which segments are glowing now.

Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from 00 to 99 inclusive.

第一行包含两个整数 nn(1≤n≤20001 \leq n \leq 2000)——计分板上的数字个数,以及 kk(0≤k≤20000 \leq k \leq 2000)——失效的线段数量。

接下来的 nn 行,每行包含一个长度为 77 的二进制字符串,其中第 ii 行表示计分板上第 ii 个数字的编码。

计分板上的每个数字由 77 根线段组成。我们按如下图所示对这些线段编号,并令该二进制字符串的第 ii 位为 00 表示第 ii 根线段不发光,为 11 表示第 ii 根线段发光。因此,一个长度为 77 的二进制字符串即可描述当前哪些线段处于发光状态。

于是,字符串序列 "1110111"、"0010010"、"1011101"、"1011011"、"0111010"、"1101011"、"1101111"、"1010010"、"1111111"、"1111011" 依次对应数字 00 至 99(含端点)。

输出格式

Output a single number consisting of nn digits — the maximum number that can be obtained if you turn on exactly kk sticks or −1-1, if it is impossible to turn on exactly kk sticks so that a correct number appears on the scoreboard digits.

输出一个由 nn 位数字组成的单个数字——即在恰好点亮 kk 根火柴棒的前提下所能得到的最大数字;若无法恰好点亮 kk 根火柴棒从而在计分板数字上显示一个合法数字,则输出 −1-1。

输入输出样例

  • 输入#1

    1 7
    0000000

    输出#1

    8
  • 输入#2

    2 5
    0010010
    0010010

    输出#2

    97
  • 输入#3

    3 5
    0100001
    1001001
    1010011

    输出#3

    -1

说明/提示

In the first test, we are obliged to include all 77 sticks and get one 88 digit on the scoreboard.

In the second test, we have sticks turned on so that units are formed. For 55 of additionally included sticks, you can get the numbers 0707, 1818, 3434, 4343, 7070, 7979, 8181 and 9797, of which we choose the maximum — 9797.

In the third test, it is impossible to turn on exactly 55 sticks so that a sequence of numbers appears on the scoreboard.

在第一个测试用例中,我们必须使用全部 77 根火柴棒,在计分板上组成一个 88 位数字。

在第二个测试用例中,已有若干根火柴棒被点亮以构成个位数字。对于额外加入的 55 根火柴棒,可以得到的数字有 0707、1818、3434、4343、7070、7979、8181 和 9797,其中最大值为 9797。

在第三个测试用例中,无法恰好点亮 55 根火柴棒,使得计分板上显示一串数字。

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

首页