CF1733D1.Zero-One (Easy Version)

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. In this version, n≤3000n \le 3000, x≥yx \ge y holds. You can make hacks only if both versions of the problem are solved.

You are given two binary strings aa and bb, both of length nn. You can do the following operation any number of times (possibly zero).

  • Select two indices ll and rr (l<rl \lt r).
  • Change ala_l to (1−al)(1 - a_l), and ara_r to (1−ar)(1 - a_r).
  • If l+1=rl + 1 = r, the cost of the operation is xx. Otherwise, the cost is yy.

You have to find the minimum cost needed to make aa equal to bb or say there is no way to do so.

这是该问题的简单版本。在此版本中,n≤3000n \le 3000,且满足 x≥yx \ge y。仅当两个版本的问题均被解决时,你才可以进行 hack。

给你两个长度均为 nn 的二进制字符串 aa 和 bb。你可以执行以下操作任意多次(包括零次):

  • 选择两个下标 ll 和 rr(满足 l<rl \lt r);
  • 将 ala_l 变为 (1−al)(1 - a_l),并将 ara_r 变为 (1−ar)(1 - a_r);
  • 若 l+1=rl + 1 = r,则该操作的代价为 xx;否则,代价为 yy。

你需要求出使 aa 等于 bb 所需的最小代价;若无法实现,则输出说明不存在可行方案。

输入格式

The first line contains one integer tt (1≤t≤6001 \le t \le 600) — the number of test cases.

Each test case consists of three lines. The first line of each test case contains three integers nn, xx, and yy (5≤n≤30005 \le n \le 3000, 1≤y≤x≤1091 \le y \le x \le 10^9) — the length of the strings, and the costs per operation.

The second line of each test case contains the string aa of length nn. The string only consists of digits 00 and 11.

The third line of each test case contains the string bb of length nn. The string only consists of digits 00 and 11.

It is guaranteed that the sum of nn over all test cases doesn't exceed 30003000.

第一行包含一个整数 tt(1≤t≤6001 \le t \le 600)—— 测试用例的数量。

每个测试用例由三行组成。每个测试用例的第一行包含三个整数 nn、xx 和 yy(5≤n≤30005 \le n \le 3000,1≤y≤x≤1091 \le y \le x \le 10^9)—— 字符串的长度以及每次操作的代价。

每个测试用例的第二行包含一个长度为 nn 的字符串 aa,该字符串仅由数字 00 和 11 组成。

每个测试用例的第三行包含一个长度为 nn 的字符串 bb,该字符串仅由数字 00 和 11 组成。

保证所有测试用例的 nn 之和不超过 30003000。

输出格式

For each test case, if there is no way to make aa equal to bb, print −1-1. Otherwise, print the minimum cost needed to make aa equal to bb.

对于每个测试用例,若无法使 aa 等于 bb,则输出 −1-1;否则,输出使 aa 等于 bb 所需的最小代价。

输入输出样例

  • 输入#1

    4
    5 8 7
    01001
    00101
    5 7 2
    01000
    11011
    7 8 3
    0111001
    0100001
    5 10 1
    01100
    01100

    输出#1

    8
    -1
    6
    0

说明/提示

In the first test case, selecting indices 22 and 33 costs 88, which is the minimum possible cost.

In the second test case, we cannot make aa equal to bb using any number of operations.

In the third test case, we can perform the following operations:

  • Select indices 33 and 66. It costs 33, and aa is 0101011 now.
  • Select indices 44 and 66. It costs 33, and aa is 0100001 now.

The total cost is 66.

In the fourth test case, we don't have to perform any operations.

在第一个测试用例中,选择下标 22 和 33 的代价为 88,这是可能的最小代价。

在第二个测试用例中,我们无法通过任意次数的操作使 aa 等于 bb。

在第三个测试用例中,我们可以执行以下操作:

  • 选择下标 33 和 66。代价为 33,此时 aa 变为 0101011。
  • 选择下标 44 和 66。代价为 33,此时 aa 变为 0100001。

总代价为 66。

在第四个测试用例中,我们无需执行任何操作。

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

首页