CF1291A.Even But Not Even

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's define a number ebne (even but not even) if and only if its sum of digits is divisible by 22 but the number itself is not divisible by 22. For example, 1313, 12271227, 185217185217 are ebne numbers, while 1212, 22, 177013177013, 265918265918 are not. If you're still unsure what ebne numbers are, you can look at the sample notes for more clarification.

You are given a non-negative integer ss, consisting of nn digits. You can delete some digits (they are not necessary consecutive/successive) to make the given number ebne. You cannot change the order of the digits, that is, after deleting the digits the remaining digits collapse. The resulting number shouldn't contain leading zeros. You can delete any number of digits between 00 (do not delete any digits at all) and n−1n-1.

For example, if you are given $s=$222373204424185217171912 then one of possible ways to make it ebne is: 222373204424185217171912 →\rightarrow 2237344218521717191. The sum of digits of 2237344218521717191 is equal to 7070 and is divisible by 22, but number itself is not divisible by 22: it means that the resulting number is ebne.

Find any resulting number that is ebne. If it's impossible to create an ebne number from the given number report about it.

我们定义一个数为 ebne 数(偶但不偶),当且仅当它的各位数字之和能被 22 整除,但该数本身不能被 22 整除。例如,1313、12271227、185217185217 是 ebne 数,而 1212、22、177013177013、265918265918 不是。如果你仍不确定 ebne 数的定义,可以参考样例说明以获得进一步澄清。

给你一个由 nn 位数字组成的非负整数 ss。你可以删除其中一些数字(这些数字不必连续),使得剩余数字构成的数为 ebne 数。你不能改变剩余数字的顺序,即删除后剩余数字会自动“坍缩”成一个新数。结果数不得包含前导零。你可以删除 00(即不删任何数字)至 n−1n-1 个数字之间的任意数量的数字。

例如,若给定 $s = $222373204424185217171912,则一种可能的构造 ebne 数的方式是:
222373204424185217171912 →\rightarrow 2237344218521717191。
该结果数 22373442185217171912237344218521717191 的各位数字之和为 7070,可被 22 整除;但该数本身是奇数(不能被 22 整除),因此它是一个 ebne 数。

请找出任意一个满足条件的 ebne 数。如果无法从给定数字中构造出 ebne 数,请报告这一点。

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤30001 \le n \le 3000) — the number of digits in the original number.

The second line of each test case contains a non-negative integer number ss, consisting of nn digits.

It is guaranteed that ss does not contain leading zeros and the sum of nn over all test cases does not exceed 30003000.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤30001 \le n \le 3000),表示原始数字的位数。

每个测试用例的第二行包含一个由 nn 位数字组成的非负整数 ss。

保证 ss 不含前导零,且所有测试用例的 nn 值之和不超过 30003000。

输出格式

For each test case given in the input print the answer in the following format:

  • If it is impossible to create an ebne number, print "-1" (without quotes);
  • Otherwise, print the resulting number after deleting some, possibly zero, but not all digits. This number should be ebne. If there are multiple answers, you can print any of them. Note that answers with leading zeros or empty strings are not accepted. It's not necessary to minimize or maximize the number of deleted digits.

对于输入中的每个测试用例,请按以下格式输出答案:

  • 如果无法构造出一个 ebne 数,则输出 \-1(不带引号);
  • 否则,输出删除若干位(可能为零位,但不能删除所有位)数字后得到的结果数。该数应为 ebne。若存在多个答案,可输出其中任意一个。注意:不允许输出带有前导零的数或空字符串。无需最小化或最大化被删除的数字位数。

输入输出样例

  • 输入#1

    4
    4
    1227
    1
    0
    6
    177013
    24
    222373204424185217171912

    输出#1

    1227
    -1
    17703
    2237344218521717191

说明/提示

In the first test case of the example, 12271227 is already an ebne number (as 1+2+2+7=121 + 2 + 2 + 7 = 12, 1212 is divisible by 22, while in the same time, 12271227 is not divisible by 22) so we don't need to delete any digits. Answers such as 127127 and 1717 will also be accepted.

In the second test case of the example, it is clearly impossible to create an ebne number from the given number.

In the third test case of the example, there are many ebne numbers we can obtain by deleting, for example, 11 digit such as 1770317703, 7701377013 or 1701317013. Answers such as 17011701 or 770770 will not be accepted as they are not ebne numbers. Answer 013013 will not be accepted as it contains leading zeroes.

Explanation:

  • 1+7+7+0+3=181 + 7 + 7 + 0 + 3 = 18. As 1818 is divisible by 22 while 1770317703 is not divisible by 22, we can see that 1770317703 is an ebne number. Same with 7701377013 and 1701317013;
  • 1+7+0+1=91 + 7 + 0 + 1 = 9. Because 99 is not divisible by 22, 17011701 is not an ebne number;
  • 7+7+0=147 + 7 + 0 = 14. This time, 1414 is divisible by 22 but 770770 is also divisible by 22, therefore, 770770 is not an ebne number.

In the last test case of the example, one of many other possible answers is given. Another possible answer is: 222373204424185217171912 →\rightarrow 22237320442418521717191 (delete the last digit).

在示例的第一个测试用例中,12271227 本身已是一个 ebne 数(因为 1+2+2+7=121 + 2 + 2 + 7 = 12,而 1212 能被 22 整除,同时 12271227 不能被 22 整除),因此无需删除任何数字。类似 127127 和 1717 的答案也同样可接受。

在示例的第二个测试用例中,显然无法从给定数字构造出一个 ebne 数。

在示例的第三个测试用例中,通过删除若干位数字(例如仅删去 11 位),我们可以得到许多 ebne 数,例如 1770317703、7701377013 或 1701317013。而像 17011701 或 770770 这样的答案则不可接受,因为它们不是 ebne 数;答案 013013 同样不可接受,因为它含有前导零。

解释:

  • 1+7+7+0+3=181 + 7 + 7 + 0 + 3 = 18。由于 1818 能被 22 整除,而 1770317703 不能被 22 整除,可知 1770317703 是一个 ebne 数;同理,7701377013 和 1701317013 也是 ebne 数;
  • 1+7+0+1=91 + 7 + 0 + 1 = 9。由于 99 不能被 22 整除,故 17011701 不是 ebne 数;
  • 7+7+0=147 + 7 + 0 = 14。此时 1414 能被 22 整除,但 770770 也能被 22 整除,因此 770770 不是 ebne 数。

在示例的最后一个测试用例中,给出了众多可能答案中的一个。另一个可能的答案是:
222373204424185217171912 →\rightarrow 22237320442418521717191(删去最后一位数字)。

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

首页