CF1906B.Button Pressing
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given N buttons (numbered from 1 to N) and N lamps (numbered from 1 to N). Each lamp can either be on or off. Initially, lamp i is on if Ai=1, and off if Ai=0.
Button i is connected to lamp i−1 (if i>1) and lamp i+1 (if i<N). In one move, you can press a button i only if lamp i is on. When a button is pressed, the state of the lamps connected to this button is toggled. Formally, the lamps will be on if it was off previously, and the lamps will be off if it was on previously. Note that lamp i is not connected to button i, thus, the state of lamp i does not change if button i is pressed.
After zero or more moves, you want lamp i to be on if Bi=1, and off if Bi=0. Determine if it is possible to achieve this task.
你有 N 个按钮(编号从 1 到 N)和 N 盏灯(编号从 1 到 N)。每盏灯的状态为“开”或“关”。初始时,若 Ai=1,则第 i 盏灯为“开”;若 Ai=0,则为“关”。
按钮 i 连接着灯 i−1(当 i>1 时)和灯 i+1(当 i<N 时)。每次操作中,你仅可在灯 i 处于“开”状态时按下按钮 i。按下按钮 i 后,所有与该按钮相连的灯的状态将被翻转:即原本“关”的变为“开”,原本“开”的变为“关”。注意,灯 i 并不连接到按钮 i,因此按下按钮 i 不会改变灯 i 的状态。
经过零次或多次操作后,你希望灯 i 处于“开”状态当且仅当 Bi=1,处于“关”状态当且仅当 Bi=0。请判断是否能达成这一目标。
输入格式
This problem has multiple test cases. The first line consists of an integer T (1≤T≤1000), which represents the number of test cases. Each test case consists of three lines.
The first line of each test case consists of an integer N (3≤N≤200000). The sum of N over all test cases does not exceed 200000.
The second line of each test case consists of a string A of length N. Each character of A can either be 0 or 1. The i-th character represents the initial state of lamp i.
The third line of each test case consists of a string A of length N. Each character of B can either be 0 or 1. The i-th character represents the desired final state of lamp i.
本题包含多个测试用例。第一行是一个整数 T(1≤T≤1000),表示测试用例的数量。每个测试用例由三行组成。
每个测试用例的第一行包含一个整数 N(3≤N≤200000)。所有测试用例的 N 值之和不超过 200000。
每个测试用例的第二行包含一个长度为 N 的字符串 A。字符串 A 的每个字符为 0 或 1,其中第 i 个字符表示第 i 盏灯的初始状态。
每个测试用例的第三行包含一个长度为 N 的字符串 B。字符串 B 的每个字符为 0 或 1,其中第 i 个字符表示第 i 盏灯的目标最终状态。
输出格式
For each test case, output YES in a single line if the final state of all lamps can be reached after zero or more moves, or NO otherwise.
对于每个测试用例,如果经过零次或多次操作后可以达到所有灯的最终状态,则在一行中输出 YES;否则输出 NO。
输入输出样例
输入#1
2 4 0101 0100 3 000 010
输出#1
YES NO
输入#2
5 7 0101011 1111010 5 11111 00000 4 1101 1101 6 101010 100100 3 000 000
输出#2
NO NO YES YES YES
说明/提示
Explanation for the sample input/output #1
For the first test case, by pressing the buttons 4,2,4,3,1,2 in sequence, the condition of the buttons changes as: 0101→0111→1101→1111→1010→1110→0100.
For the second test case, you are unable to press any button, hence it is impossible to reach the final state.
样例输入/输出 #1 的解释
对于第一个测试用例,依次按下按钮 4,2,4,3,1,2 后,按钮状态的变化过程为:0101→0111→1101→1111→1010→1110→0100。
对于第二个测试用例,你无法按下任何按钮,因此不可能达到最终状态。
输入解题思路,AI测评打分。不知道怎么写?