A11344 | Make it White
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You have a horizontal strip of $n$ cells. Each cell is either white or black.
You can choose a continuous segment of cells once and paint them all white. After this action, all the black cells in this segment will become white, and the white ones will remain white.
What is the minimum length of the segment that needs to be painted white in order for all $n$ cells to become white?
You can choose a continuous segment of cells once and paint them all white. After this action, all the black cells in this segment will become white, and the white ones will remain white.
What is the minimum length of the segment that needs to be painted white in order for all $n$ cells to become white?
输入格式
The first line of the input contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains a single integer $n$ ( $1 \le n \le 10$ ) — the length of the strip.
The second line of each test case contains a string $s$ , consisting of $n$ characters, each of which is either 'W' or 'B'. The symbol 'W' denotes a white cell, and 'B' — a black one. It is guaranteed that at least one cell of the given strip is black.
The first line of each test case contains a single integer $n$ ( $1 \le n \le 10$ ) — the length of the strip.
The second line of each test case contains a string $s$ , consisting of $n$ characters, each of which is either 'W' or 'B'. The symbol 'W' denotes a white cell, and 'B' — a black one. It is guaranteed that at least one cell of the given strip is black.
输出格式
For each test case, output a single number — the minimum length of a continuous segment of cells that needs to be painted white in order for the entire strip to become white.
输入输出样例
输入 #1
8 6 WBBWBW 1 B 2 WB 3 BBW 4 BWWB 6 BWBWWB 6 WWBBWB 9 WBWBWWWBW
输出 #1
4 1 1 2 4 6 4 7
In the first test case of the example for the strip "WBBWBW", the minimum length of the segment to be repainted white is $4$ . It is necessary to repaint to white the segment from the $2$ -nd to the $5$ -th cell (the cells are numbered from $1$ from left to right).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted