A13719 | Balanced Bitstring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A bitstring is a string consisting only of the characters 0 and 1. A bitstring is called $k$ -balanced if every substring of size $k$ of this bitstring has an equal amount of 0 and 1 characters ( $\frac{k}{2}$ of each).
You are given an integer $k$ and a string $s$ which is composed only of characters 0, 1, and ?. You need to determine whether you can make a $k$ -balanced bitstring by replacing every ? characters in $s$ with either 0 or 1.
A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
You are given an integer $k$ and a string $s$ which is composed only of characters 0, 1, and ?. You need to determine whether you can make a $k$ -balanced bitstring by replacing every ? characters in $s$ with either 0 or 1.
A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 10^4$ ). Description of the test cases follows.
The first line of each test case contains two integers $n$ and $k$ ( $2 \le k \le n \le 3 \cdot 10^5$ , $k$ is even) — the length of the string and the parameter for a balanced bitstring.
The next line contains the string $s$ ( $|s| = n$ ). It is given that $s$ consists of only 0, 1, and ?.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$ .
The first line of each test case contains two integers $n$ and $k$ ( $2 \le k \le n \le 3 \cdot 10^5$ , $k$ is even) — the length of the string and the parameter for a balanced bitstring.
The next line contains the string $s$ ( $|s| = n$ ). It is given that $s$ consists of only 0, 1, and ?.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$ .
输出格式
For each test case, print YES if we can replace every ? in $s$ with 0 or 1 such that the resulting bitstring is $k$ -balanced, or NO if it is not possible.
输入输出样例
输入 #1
9 6 4 100110 3 2 1?1 3 2 1?0 4 4 ???? 7 4 1?0??1? 10 10 11??11??11 4 2 1??1 4 4 ?0?0 6 2 ????00
输出 #1
YES YES NO YES YES NO NO YES NO
For the first test case, the string is already a $4$ -balanced bitstring.
For the second test case, the string can be transformed into 101.
For the fourth test case, the string can be transformed into 0110.
For the fifth test case, the string can be transformed into 1100110.
For the second test case, the string can be transformed into 101.
For the fourth test case, the string can be transformed into 0110.
For the fifth test case, the string can be transformed into 1100110.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted