#P7853. 「EZEC-9」进位

    ID: 6650 远端评测题 500ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2021Special Judge枚举,暴力洛谷月赛

「EZEC-9」进位

Description

You are given a binary number BB (provided as a 0101 string of length nn) and a sequence aa of length mm.

You also need to perform mm operations on BB.

In the ii-th operation, BB+2aiB \gets B + 2^{a_i}. Its value viv_i is the number of bit positions that change in BB before and after the operation, i.e., $v_i = \operatorname{popcount}(B \mathbin{\mathrm{xor}} (B + 2^{a_i}))$.

You need to solve two problems:

  • You may arrange the order of operations arbitrarily. After performing all operations, what is the maximum possible value of i=1mvi\displaystyle \sum_{i=1}^m v_i?

  • You may arrange the order of operations arbitrarily. After performing all operations, what is the maximum possible value of maxi=1mvi\displaystyle \max_{i=1}^m v_i?

Input Format

The first line contains two integers n,mn, m.

The second line contains a 0101 string of length nn, representing the binary number BB, given from the least significant bit to the most significant bit.

The third line contains mm integers a1,a2,,ama_1, a_2, \dots, a_m.

Output Format

The first line contains one integer, the answer to the first question.

The second line contains one integer, the answer to the second question.

This problem uses Special Judge. If your answer to the first question is correct, you can get 30%30\% of the score for that test point. If your answer to the second question is correct, you can get another 70%70\% of the score for that test point.

If you answer only one of the two questions, please output a non-negative integer in the other position.

5 6
10110
1 0 2 2 2 2

14
6

10 10
0101010110
0 1 2 3 4 5 5 4 3 2

21
9

10 3
1111101111
5 5 0

13
11

Hint

[Sample Explanation #1]

For the first question, performing operations 1,2,6,5,4,31, 2, 6, 5, 4, 3 in order can achieve i=1mvi=14\displaystyle \sum\limits_{i=1}^m v_i = 14.

For the second question, performing operations 6,5,4,3,1,26, 5, 4, 3, 1, 2 in order can achieve maxi=1mvi=6\displaystyle \max\limits_{i=1}^m v_i = 6.

Detailed process

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (20 points): n,m10n, m \leq 10.
  • Subtask 2 (30 points): n,m1000n, m \leq 1000.
  • Subtask 3 (20 points): BB is all 00, and a1=0a_1 = 0, i>1,ai1aiai1+1\forall i>1, a_{i-1} \leq a_i \leq a_{i-1} + 1.
  • Subtask 4 (20 points): n,m105n, m \leq 10^5.
  • Subtask 5 (10 points): no special restrictions.

For 100%100\% of the testdata, 1n,m1061 \leq n, m \leq 10^6, 0ai<n0 \leq a_i < n.

Translated by ChatGPT 5