CF1297H.Paint the String

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a string ss of lowercase Latin letters. It is required to paint each letter of the string in one of two colors (red or blue) so that if you write all the red letters from left to right and write all the blue letters from left to right, then the lexicographically maximum of the two written strings is lexicographically minimal. For each index, in the string ss you can choose either of two colors.

Formally, we write out:

  • the string rr (can be empty) — all red letters in the order from left to right (red subsequence),
  • the string bb (can be empty) — all blue letters in the order from left to right (blue subsequence).

Your task is to paint the string such that max⁡(r,b)\max(r, b) is minimal. Small reminder: the empty string is the lexicographically smallest string.

给你一个由小写拉丁字母组成的字符串 ss。你需要将字符串中的每个字母涂成两种颜色之一(红色或蓝色),使得:将所有红色字母从左到右写出(构成字符串 rr),并将所有蓝色字母从左到右写出(构成字符串 bb)后,max⁡(r,b)\max(r, b) 的字典序尽可能小。对字符串 ss 中的每个位置,你均可任选两种颜色之一。

形式化地,我们定义:

  • 字符串 rr(可能为空)—— 所有红色字母按从左到右顺序组成的子序列(红色子序列),
  • 字符串 bb(可能为空)—— 所有蓝色字母按从左到右顺序组成的子序列(蓝色子序列)。

你的任务是给字符串染色,使得 max⁡(r,b)\max(r, b) 的字典序最小。小提示:空字符串是字典序最小的字符串。

输入格式

The first line contains an integer tt (1≤t≤1001 \le t \le 100) — the number of test cases in the test. Next, the test cases are given, one per line.

Each test case is a non-empty string ss of length between 22 to 100100 characters, inclusive, which consists of lowercase Latin letters.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。接下来每行给出一个测试用例。

每个测试用例是一个非空字符串 ss,其长度在 22 到 100100 个字符之间(含端点),且仅由小写拉丁字母组成。

输出格式

Print tt lines, the ii-th of them should contain the answer to the ii-th test case of the input. Print a string of length nn, where nn is the length of the given string ss: the jj-th character of the string should be either 'R'or 'B' depending on the color of the jj-th character in the answer (painted in red or blue). If there are several possible answers, print any of them.

输出 tt 行,其中第 ii 行应包含输入中第 ii 个测试用例的答案。输出一个长度为 nn 的字符串,其中 nn 是给定字符串 ss 的长度:该字符串的第 jj 个字符应为 'R' 或 'B',分别表示答案中第 jj 个字符所涂的颜色(红色或蓝色)。若存在多个可能的答案,输出任意一个即可。

输入输出样例

  • 输入#1

    5
    kotlin
    codeforces
    abacaba
    ffccgc
    yz

    输出#1

    RRRRBB
    RRRRRRRBBB
    RRRRBBB
    RBBBBR
    RR

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

首页