A14977 | Detective Task
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp bought a new expensive painting and decided to show it to his $n$ friends. He hung it in his room. $n$ of his friends entered and exited there one by one. At one moment there was no more than one person in the room. In other words, the first friend entered and left first, then the second, and so on.
It is known that at the beginning (before visiting friends) a picture hung in the room. At the end (after the $n$ -th friend) it turned out that it disappeared. At what exact moment it disappeared — there is no information.
Polycarp asked his friends one by one. He asked each one if there was a picture when he entered the room. Each friend answered one of three:
- no (response encoded with 0);
- yes (response encoded as 1);
- can't remember (response is encoded with ?).
Everyone except the thief either doesn't remember or told the truth. The thief can say anything (any of the three options).
Polycarp cannot understand who the thief is. He asks you to find out the number of those who can be considered a thief according to the answers.
It is known that at the beginning (before visiting friends) a picture hung in the room. At the end (after the $n$ -th friend) it turned out that it disappeared. At what exact moment it disappeared — there is no information.
Polycarp asked his friends one by one. He asked each one if there was a picture when he entered the room. Each friend answered one of three:
- no (response encoded with 0);
- yes (response encoded as 1);
- can't remember (response is encoded with ?).
Everyone except the thief either doesn't remember or told the truth. The thief can say anything (any of the three options).
Polycarp cannot understand who the thief is. He asks you to find out the number of those who can be considered a thief according to the answers.
输入格式
The first number $t$ ( $1 \le t \le 10^4$ ) — the number of test cases in the test.
The following is a description of test cases.
The first line of each test case contains one string $s$ (length does not exceed $2 \cdot 10^5$ ) — a description of the friends' answers, where $s_i$ indicates the answer of the $i$ -th friend. Each character in the string is either 0 or 1 or ?.
The given regularity is described in the actual situation. In particular, on the basis of answers, at least one friend can be suspected of stealing a painting.
It is guaranteed that the sum of string lengths over the entire input data set does not exceed $2 \cdot 10^5$ .
The following is a description of test cases.
The first line of each test case contains one string $s$ (length does not exceed $2 \cdot 10^5$ ) — a description of the friends' answers, where $s_i$ indicates the answer of the $i$ -th friend. Each character in the string is either 0 or 1 or ?.
The given regularity is described in the actual situation. In particular, on the basis of answers, at least one friend can be suspected of stealing a painting.
It is guaranteed that the sum of string lengths over the entire input data set does not exceed $2 \cdot 10^5$ .
输出格式
Output one positive (strictly more zero) number – the number of people who could steal the picture based on the data shown.
输入输出样例
输入 #1
8 0 1 1110000 ????? 1?1??0?0 0?0??? ??11 ??0??
输出 #1
1 1 2 5 4 1 1 3
In the first case, the answer is $1$ since we had exactly $1$ friend.
The second case is similar to the first.
In the third case, the suspects are the third and fourth friends (we count from one). It can be shown that no one else could be the thief.
In the fourth case, we know absolutely nothing, so we suspect everyone.
The second case is similar to the first.
In the third case, the suspects are the third and fourth friends (we count from one). It can be shown that no one else could be the thief.
In the fourth case, we know absolutely nothing, so we suspect everyone.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted