AT_arc223_e.Yin-Yang Two Bits Insertion

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given integer sequences A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N) and B=(B1,B2,…,BM)B=(B_1,B_2,\dots,B_M) of length 22 or more, consisting of 00s and 11s.
You can perform the following operation on AA any number of times:

  • Choose an integer ii satisfying 1≤i≤∣A∣−11 \leq i \leq |A|-1.
  • Insert 1−Ai1-A_i and 1−Ai+11-A_{i+1} in this order between AiA_i and Ai+1A_{i+1}.

Determine whether it is possible to make AA equal to BB.

Solve TT test cases per input.

给你两个长度至少为 22 的由 00 和 11 构成的整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N) 和 B=(B1,B2,…,BM)B=(B_1,B_2,\dots,B_M)。
你可以在 AA 上执行以下操作任意多次:

  • 选择一个满足 1≤i≤∣A∣−11 \leq i \leq |A|-1 的整数 ii;
  • 在 AiA_i 和 Ai+1A_{i+1} 之间按顺序插入 1−Ai1-A_i 和 1−Ai+11-A_{i+1}。

判断是否可能通过若干次操作使 AA 变为 BB。

每组输入包含 TT 个测试用例,需全部求解。

输入格式

The input is given from Standard Input in the following format:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case caset\mathrm{case}_t is given in the following format:

NN MM
A1A_1 A2A_2 …\dots ANA_N
B1B_1 B2B_2 …\dots BMB_M

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例 caset\mathrm{case}_t 按以下格式给出:

NN MM
A1A_1 A2A_2 …\dots ANA_N
B1B_1 B2B_2 …\dots BMB_M

输出格式

Output the answers over a total of TT lines. The tt-th line should contain Yes if it is possible to make AA equal to BB for the tt-th test case, and No otherwise.

在总共 TT 行中输出答案。第 tt 行应包含 Yes(如果第 tt 个测试用例中可以使 AA 等于 BB),否则包含 No。

输入输出样例

  • 输入#1

    3
    3 7
    0 1 1
    0 1 0 1 1 0 1
    2 4
    0 1
    0 1 0 1
    3 4
    0 0 0
    0 0 0 1

    输出#1

    Yes
    Yes
    No

说明/提示

Sample 1 Explanation:
For the first test case, initially A=(0,1,1)A=(0,1,1).
First, choosing i=2i=2 gives A=(0,1,0,0,1)A=(0,1,0,0,1).
Next, choosing i=3i=3 gives A=(0,1,0,1,1,0,1)A=(0,1,0,1,1,0,1).

Constraints

  • 1≤T≤1051 \leq T \leq 10^5
  • 2≤N≤M≤2×1052 \leq N \leq M \leq 2 \times 10^5
  • Ai,Bi∈0,1A_i, B_i \in {0,1}
  • The sum of N+MN+M over all test cases is at most 4×1054 \times 10^5.
  • All input values are integers.

样例 1 解释:
对于第一个测试用例,初始时 A=(0,1,1)A=(0,1,1)。
首先,选择 i=2i=2,得到 A=(0,1,0,0,1)A=(0,1,0,0,1)。
接着,选择 i=3i=3,得到 A=(0,1,0,1,1,0,1)A=(0,1,0,1,1,0,1)。

约束条件

  • 1≤T≤1051 \leq T \leq 10^5
  • 2≤N≤M≤2×1052 \leq N \leq M \leq 2 \times 10^5
  • Ai,Bi∈{0,1}A_i, B_i \in \{0,1\}
  • 所有测试用例中 N+MN+M 的总和不超过 4×1054 \times 10^5。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页