CF79D.Password

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Finally Fox Ciel arrived in front of her castle!

She have to type a password to enter her castle. An input device attached to her castle is a bit unusual.

The input device is a 1 × n rectangle divided into n square panels. They are numbered 1 to n from left to right. Each panel has a state either ON or OFF. Initially all panels are in the OFF state. She can enter her castle if and only if _x_1-th, _x_2-th, ..., x__k-th panels are in the ON state and other panels are in the OFF state.

She is given an array _a_1, ..., a__l. In each move, she can perform the following operation: choose an index i (1 ≤ i ≤ l), choose consecutive a__i panels, and flip the states of those panels (i.e. ON → OFF, OFF → ON).

Unfortunately she forgets how to type the password with only above operations. Determine the minimal number of operations required to enter her castle.

最终,小狐狸雪儿抵达了她的城堡前!

她需要输入密码才能进入城堡。连接在城堡上的输入设备有些特别。

该输入设备是一个 1×n1 \times n 的矩形,被划分为 nn 个正方形面板,从左到右编号为 11 到 nn。每个面板的状态为“开(ON)”或“关(OFF)”。初始时所有面板均为“关(OFF)”状态。当且仅当第 x1x_1、x2x_2、…、xkx_k 个面板处于“开(ON)”状态,而其余面板均处于“关(OFF)”状态时,她才能进入城堡。

她被给定一个数组 a1,…,ala_1, \dots, a_l。在每次操作中,她可以执行以下操作:选择一个下标 ii(满足 1≤i≤l1 \le i \le l),再选择一段连续的 aia_i 个面板,并翻转这些面板的状态(即 ON → OFF,OFF → ON)。

不幸的是,她忘记了仅用上述操作输入密码的方法。请确定进入城堡所需的最少操作次数。

输入格式

The first line contains three integers n, k and l (1 ≤ n ≤ 10000, 1 ≤ k ≤ 10, 1 ≤ l ≤ 100), separated by single spaces.

The second line contains k integers _x_1, ..., x__k (1 ≤ _x_1 < _x_2 < ... < x__k ≤ n), separated by single spaces.

The third line contains l integers _a_1, ..., a__l (1 ≤ a__i ≤ n), separated by single spaces. It is possible that some elements of the array a__i are equal value.

第一行包含三个整数 nn、kk 和 ll(1 ≤ n ≤ 100001 ≤ n ≤ 10000,1 ≤ k ≤ 101 ≤ k ≤ 10,1 ≤ l ≤ 1001 ≤ l ≤ 100),以单个空格分隔。

第二行包含 kk 个整数 x1,…,xkx_1, \dots, x_k(1 ≤ x1 < x2 < … < xk ≤ n1 ≤ x_1 < x_2 < \dots < x_k ≤ n),以单个空格分隔。

第三行包含 ll 个整数 a1,…,ala_1, \dots, a_l(1 ≤ ai ≤ n1 ≤ a_i ≤ n),以单个空格分隔。数组 aia_i 中的某些元素可能取值相等。

输出格式

Print the minimal number of moves required to type the password. If it's impossible, print -1.

输出输入密码所需的最少移动次数。如果无法输入,则输出 −1-1。

输入输出样例

  • 输入#1

    10 8 2
    1 2 3 5 6 7 8 9
    3 5

    输出#1

    2
  • 输入#2

    3 2 1
    1 2
    3

    输出#2

    -1

说明/提示

One possible way to type the password in the first example is following: In the first move, choose 1st, 2nd, 3rd panels and flip those panels. In the second move, choose 5th, 6th, 7th, 8th, 9th panels and flip those panels.

第一个示例中输入密码的一种可能方式如下:在第一次操作中,选择第 1、第 2 和第 3 个面板并翻转这些面板;在第二次操作中,选择第 5、第 6、第 7、第 8 和第 9 个面板并翻转这些面板。

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

首页