CF1669D.Colorful Stamp
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A row of n cells is given, all initially white. Using a stamp, you can stamp any two neighboring cells such that one becomes red and the other becomes blue. A stamp can be rotated, i.e. it can be used in both ways: as BR and as RB.
During use, the stamp must completely fit on the given n cells (it cannot be partially outside the cells). The stamp can be applied multiple times to the same cell. Each usage of the stamp recolors both cells that are under the stamp.
For example, one possible sequence of stamps to make the picture BRBBW could be WWWWW→WWRBW→BRRBW→BRBBW. Here W, R, and B represent a white, red, or blue cell, respectively, and the cells that the stamp is used on are marked with an underline.
Given a final picture, is it possible to make it using the stamp zero or more times?
给定一排 n 个格子,初始时全部为白色。你可以使用一个印章,将其盖在任意两个相邻的格子上,使得其中一个变为红色,另一个变为蓝色。该印章可以旋转,即可以以两种方式使用:BR 或 RB。
使用印章时,它必须完全落在给定的 n 个格子范围内(不能部分超出格子边界)。同一格子可被多次盖章。每次盖章都会重绘印章所覆盖的两个格子的颜色。
例如,要得到目标图案 BRBBW,一种可能的盖章序列为:
WWWWW→WWRBW→BRRBW→BRBBW。
其中,W、R 和 B 分别表示白色、红色和蓝色格子,下划线标出了每次盖章所覆盖的格子。
给定一个最终图案,判断是否可以通过零次或多次使用该印章来实现?
输入格式
The first line contains an integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains an integer n (1≤n≤105) — the length of the picture.
The second line of each test case contains a string s — the picture you need to make. It is guaranteed that the length of s is n and that s only consists of the characters W, R, and B, representing a white, red, or blue cell, respectively.
It is guaranteed that the sum of n over all test cases does not exceed 105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤105)—— 图片的长度。
每个测试用例的第二行包含一个字符串 s —— 你需要构造的图片。保证 s 的长度为 n,且 s 仅由字符 W、R 和 B 组成,分别表示白色、红色和蓝色的格子。
保证所有测试用例的 n 之和不超过 105。
输出格式
Output t lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if it possible to make the picture using the stamp zero or more times, and "NO" otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
输出 t 行,每行包含对应测试用例的答案。若能通过零次或多次使用该印章制作出该图案,则输出 "YES";否则输出 "NO"。
答案的大小写不限(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均被视为正确答案)。
输入输出样例
输入#1
12 5 BRBBW 1 B 2 WB 2 RW 3 BRB 3 RBB 7 WWWWWWW 9 RBWBWRRBW 10 BRBRBRBRRB 12 BBBRWWRRRWBR 10 BRBRBRBRBW 5 RBWBW
输出#1
YES NO NO NO YES YES YES NO YES NO YES NO
说明/提示
The first test case is explained in the statement.
For the second, third, and fourth test cases, it is not possible to stamp a single cell, so the answer is "NO".
For the fifth test case, you can use the stamp as follows: WWW→WRB→BRB.
For the sixth test case, you can use the stamp as follows: WWW→WRB→RBB.
For the seventh test case, you don't need to use the stamp at all.
第一个测试用例已在题目描述中说明。
对于第二、第三和第四个测试用例,无法仅盖印一个单元格,因此答案为“NO”。
对于第五个测试用例,你可以按如下方式使用印章:WWW→WRB→BRB。
对于第六个测试用例,你可以按如下方式使用印章:WWW→WRB→RBB。
对于第七个测试用例,你完全不需要使用印章。
输入解题思路,AI测评打分。不知道怎么写?