CF1209C.Paint the Digits

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a sequence of nn digits d1d2…dnd_1d_2 \dots d_{n}. You need to paint all the digits in two colors so that:

  • each digit is painted either in the color 11 or in the color 22;
  • if you write in a row from left to right all the digits painted in the color 11, and then after them all the digits painted in the color 22, then the resulting sequence of nn digits will be non-decreasing (that is, each next digit will be greater than or equal to the previous digit).

For example, for the sequence d=914d=914 the only valid coloring is 211211 (paint in the color 11 two last digits, paint in the color 22 the first digit). But 122122 is not a valid coloring (99 concatenated with 1414 is not a non-decreasing sequence).

It is allowed that either of the two colors is not used at all. Digits painted in the same color are not required to have consecutive positions.

Find any of the valid ways to paint the given sequence of digits or determine that it is impossible to do.

给你一个由 nn 个数字组成的序列 d1d2…dnd_1d_2 \dots d_{n}。你需要将所有数字涂上两种颜色之一,使得:

  • 每个数字被涂成颜色 11 或颜色 22;
  • 若将所有涂成颜色 11 的数字从左到右依次写出,紧接着再将所有涂成颜色 22 的数字从左到右依次写出,则得到的 nn 位数字序列是非递减的(即每个后续数字均大于或等于前一个数字)。

例如,对于序列 d=914d=914,唯一有效的涂色方案是 211211(将后两个数字涂成颜色 11,第一个数字涂成颜色 22)。但 122122 不是有效方案(将 99 与 1414 拼接得到 914914,该序列不是非递减的)。

允许其中一种颜色完全不使用。涂成同一种颜色的数字不要求位置连续。

请找出任意一种满足条件的涂色方案,或判定该问题无解。

输入格式

The first line contains a single integer tt (1≤t≤100001 \le t \le 10000) — the number of test cases in the input.

The first line of each test case contains an integer nn (1≤n≤2⋅1051 \le n \le 2\cdot10^5) — the length of a given sequence of digits.

The next line contains a sequence of nn digits d1d2…dnd_1d_2 \dots d_{n} (0≤di≤90 \le d_i \le 9). The digits are written in a row without spaces or any other separators. The sequence can start with 0.

It is guaranteed that the sum of the values of nn for all test cases in the input does not exceed 2⋅1052\cdot10^5.

第一行包含一个整数 tt(1≤t≤100001 \le t \le 10000)—— 输入中测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2\cdot10^5)—— 给定数字序列的长度。

接下来一行包含 nn 个数字 d1d2…dnd_1d_2 \dots d_{n}(0≤di≤90 \le d_i \le 9)。这些数字连续书写,中间不包含空格或其他分隔符。该序列可能以 0 开头。

保证输入中所有测试用例的 nn 值之和不超过 2⋅1052\cdot10^5。

输出格式

Print tt lines — the answers to each of the test cases in the input.

If there is a solution for a test case, the corresponding output line should contain any of the valid colorings written as a string of nn digits t1t2…tnt_1t_2 \dots t_n (1≤ti≤21 \le t_i \le 2), where tit_i is the color the ii-th digit is painted in. If there are several feasible solutions, print any of them.

If there is no solution, then the corresponding output line should contain a single character '-' (the minus sign).

输出 tt 行——对应输入中每个测试用例的答案。

若某个测试用例存在解,则对应的输出行应包含任意一个有效的染色方案,表示为一个长度为 nn 的数字字符串 t1t2…tnt_1t_2 \dots t_n(其中 1≤ti≤21 \le t_i \le 2),tit_i 表示第 ii 个数字所染的颜色。若存在多个可行解,输出任意一个即可。

若不存在解,则对应的输出行应仅包含一个字符 \-(减号)。

输入输出样例

  • 输入#1

    5
    12
    040425524644
    1
    0
    9
    123456789
    2
    98
    3
    987

    输出#1

    121212211211
    1
    222222222
    21
    -

说明/提示

In the first test case, d=040425524644d=040425524644. The output t=121212211211t=121212211211 is correct because 00224440022444 (painted in 11) concatenated with 4455644556 (painted in 22) is 002244444556002244444556 which is a sorted sequence of nn given digits.

在第一个测试用例中,d=040425524644d=040425524644。输出 t=121212211211t=121212211211 是正确的,因为将数字 00224440022444(涂成 11)与 4455644556(涂成 22)拼接得到 002244444556002244444556,这恰好是给定的 nn 个数字的升序排列。

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

首页