QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#18116. 湖畔牛迟到的原因 6

统计

Hobanwoo 终于到达了魔王城,但魔王城的门锁着,他无法进入。

为了打开魔王城的门,需要将长度为 $N$ 的魔法钥匙转换为长度恰好为 $M$ 的魔法钥匙,并使魔法钥匙的力量最大化。

长度为 $N$ 的魔法钥匙由 $N$ 个非负整数组成的序列 $a_{1},\,\,a_{2},\,\,a_{3}\,,\cdots,\,a_{N}$ 表示,长度为 $N$ 的魔法钥匙的力量定义为序列中 $N$ 个数的总和。

当当前魔法钥匙的长度为 $ℓ$ 时,可以通过对魔法钥匙应用以下 $4$ 种魔法之一来缩短其长度:

  • 从魔法钥匙中移除 $a_{1},\,a_{2}$,并在前端添加 $a_{1}⊕a_{2}$,从而制造出长度为 $ℓ-1$ 的新魔法钥匙。
  • 从魔法钥匙中移除 $a_{ℓ-1},\,a_{ℓ}$,并在后端添加 $a_{ℓ-1}⊕a_{ℓ}$,从而制造出长度为 $ℓ-1$ 的新魔法钥匙。
  • 从魔法钥匙中移除 $a_{1},\,a_{2},\,a_{3},\,a_{4}$,并在前端添加 $a_{2}⊕a_{3},\,a_{1}⊕a_{4}$,从而制造出长度为 $ℓ-2$ 的新魔法钥匙。
  • 从魔法钥匙中移除 $a_{ℓ-3},\,a_{ℓ-2},\,a_{ℓ-1},\,a_{ℓ}$,并在后端添加 $a_{ℓ-3}⊕a_{ℓ},\,a_{ℓ-2}⊕a_{ℓ-1}$,从而制造出长度为 $ℓ-2$ 的新魔法钥匙。

每次操作的序列变化如下所示:

$({\color{Red}a_{{\color{Red}1}}},\,\,{\color{Red}a_{{\color{Red}2}}},\,\,a_{3},\,\,a_{4}\,,\cdots,\,a_{ℓ}) \Rightarrow ({\color{Red}a_{{\color{Red}1}}}{\color{Red}⊕}{\color{Red}a_{{\color{Red}2}}},\,\,a_{3},\,\,a_{4}\,,\cdots,\,a_{ℓ})$ $(a_{1}\,,\cdots,\,a_{ℓ-3},\,\,a_{ℓ-2},\,\,{\color{Red}a_{{\color{Red}ℓ{\color{Red}-}{\color{Red}1}}}},\,\,{\color{Red}a_{{\color{Red}ℓ}}}) \Rightarrow (a_{1}\,,\cdots,\,a_{ℓ-3},\,\,a_{ℓ-2},\,\,{\color{Red}a_{{\color{Red}ℓ}{\color{Red}-}{\color{Red}1}}}{\color{Red}⊕}{\color{Red}a_{{\color{Red}ℓ}}})$ $({\color{Red}a_{{\color{Red}1}}},\,\,{\color{Blue}a_{{\color{Blue}2}}},\,\,{\color{Blue}a_{{\color{Blue}3}}},\,\,{\color{Red}a_{{\color{Red}4}}},\,\,a_{5},\,\,a_{6}\,,\cdots,\,a_{ℓ}) \Rightarrow ({\color{Blue}a_{{\color{Blue}2}}}{\color{Blue}⊕}{\color{Blue}a_{{\color{Blue}3}}},\,\,{\color{Red}a_{{\color{Red}1}}}{\color{Red}⊕}{\color{Red}a_{{\color{Red}4}}},\,\,a_{5},\,\,a_{6}\,,\cdots,\,a_{ℓ})$ $(a_{1}\,,\cdots,\,a_{ℓ-5},\,\,a_{ℓ-4},\,\,{\color{Red}a_{{\color{Red}ℓ}{\color{Red}-}{\color{Red}3}}},\,\,{\color{Blue}a_{{\color{Blue}ℓ}{\color{Blue}-}{\color{Blue}2}}},\,\,{\color{Blue}a_{{\color{Blue}ℓ}{\color{Blue}-}{\color{Blue}1}}},\,\,{\color{Red}a_{{\color{Red}ℓ}}}) \Rightarrow (a_{1}\,,\cdots,\,a_{ℓ-5},\,\,a_{ℓ-4},\,\,{\color{Red}a_{{\color{Red}ℓ}{\color{Red}-}{\color{Red}3}}}{\color{Red}⊕}{\color{Red}a_{{\color{Red}ℓ}}},\,\,{\color{Blue}a_{{\color{Blue}ℓ}{\color{Blue}-}{\color{Blue}2}}}{\color{Blue}⊕}{\color{Blue}a_{{\color{Blue}ℓ}{\color{Blue}-}{\color{Blue}1}}})$

请帮助 Hobanwoo 打开魔王城的门!

输入格式

第一行包含两个整数 $N$ 和 $M$,中间用空格隔开。$(4 \le M \le N \le 5\,000)$

第二行包含 $N$ 个整数 $a_{1},\,\,a_{2},\,\,a_{3}\,,\cdots,\,a_{N}$,中间用空格隔开。$(0 \le a_{i} \le 10^{9})$

输出格式

输出当制造出长度为 $M$ 的魔法钥匙时,可能获得的最大魔法钥匙力量。

说明

⊕ 表示按位异或(Bitwise XOR)运算,按位进行计算。

按位异或(Bitwise XOR) 对两个数的每一位进行如下运算: 如果两个位不同,则结果为 $1$,否则为 $0$。 示例: $$ \begin{aligned} 0110_{2} &= 6 \\ \text{⊕} \ \ 1100_{2} &= 12 \\ \text{────} \\ 1010_{2} &= 10 \end{aligned} $$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.