CF1328C.Ternary XOR

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A number is ternary if it contains only digits 00, 11 and 22. For example, the following numbers are ternary: 10221022, 1111, 2121, 20022002.

You are given a long ternary number xx. The first (leftmost) digit of xx is guaranteed to be 22, the other digits of xx can be 00, 11 or 22.

Let's define the ternary XOR operation ⊙\odot of two ternary numbers aa and bb (both of length nn) as a number c=a⊙bc = a \odot b of length nn, where ci=(ai+bi)%3c_i = (a_i + b_i) \% 3 (where %\% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 33. For example, 10222⊙11021=2121010222 \odot 11021 = 21210.

Your task is to find such ternary numbers aa and bb both of length nn and both without leading zeros that a⊙b=xa \odot b = x and max(a,b)max(a, b) is the minimum possible.

You have to answer tt independent test cases.

一个数被称为三进制数,当且仅当它仅由数字 00、11 和 22 组成。例如,以下数均为三进制数:10221022、1111、2121、20022002。

给定一个长度很长的三进制数 xx。已知 xx 的首位(最左侧)数字必定为 22,其余各位可为 00、11 或 22。

我们定义两个等长(长度均为 nn)的三进制数 aa 和 bb 的三进制异或运算 ⊙\odot 为一个长度为 nn 的三进制数 c=a⊙bc = a \odot b,其中第 ii 位满足 ci=(ai+bi)%3c_i = (a_i + b_i) \% 3(%\% 表示取模运算)。换言之,将对应位上的数字相加,再对 33 取余。例如,10222⊙11021=2121010222 \odot 11021 = 21210。

你的任务是找出两个长度均为 nn、且均无前导零的三进制数 aa 和 bb,使得 a⊙b=xa \odot b = x,并使 max⁡(a,b)\max(a, b) 尽可能小。

你需要回答 tt 个相互独立的测试用例。

输入格式

The first line of the input contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Then tt test cases follow. The first line of the test case contains one integer nn (1≤n≤5⋅1041 \le n \le 5 \cdot 10^4) — the length of xx. The second line of the test case contains ternary number xx consisting of nn digits 0,10, 1 or 22. It is guaranteed that the first digit of xx is 22. It is guaranteed that the sum of nn over all test cases does not exceed 5⋅1045 \cdot 10^4 (∑n≤5⋅104\sum n \le 5 \cdot 10^4).

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。接下来是 tt 个测试用例。每个测试用例的第一行包含一个整数 nn(1≤n≤5⋅1041 \le n \le 5 \cdot 10^4),表示三进制数 xx 的长度。每个测试用例的第二行包含一个由 nn 位数字 00、11 或 22 组成的三进制数 xx。保证 xx 的第一位数字为 22。保证所有测试用例的 nn 值之和不超过 5⋅1045 \cdot 10^4(即 ∑n≤5⋅104\sum n \le 5 \cdot 10^4)。

输出格式

For each test case, print the answer — two ternary integers aa and bb both of length nn and both without leading zeros such that a⊙b=xa \odot b = x and max(a,b)max(a, b) is the minimum possible. If there are several answers, you can print any.

对于每个测试用例,输出答案——两个长度均为 nn 且均无前导零的三进制整数 aa 和 bb,使得 a⊙b=xa \odot b = x,且 max⁡(a,b)\max(a, b) 尽可能小。若存在多个满足条件的答案,输出任意一个即可。

输入输出样例

  • 输入#1

    4
    5
    22222
    5
    21211
    1
    2
    9
    220222021

    输出#1

    11111
    11111
    11000
    10211
    1
    1
    110111011
    110111010

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

首页