logo AlgoBeat OnlineJudge
登录 注册

#210691. [HBCPC2024] MACARON Likes Happy Endings

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

MACARON is going to read a book, which contains chapters, and the -th chapter has characters. MACARON wants to read this book in the next days. On each day, he either reads several chapters from the first unread chapter, or just takes a rest (does not read the book), but he should finish his reading in days.

MACARON enjoys his reading time and likes happy endings, so he does not want to be too sad during these days. He has an unlucky number , because he thinks number will lead to a bad ending. We use a sadness value to quantify his mood on each day. On the -th day, if he reads, suppose that he reads chapters from to . The sadness value of this day is the number of intervals such that and . The denotes the bitwise XOR operator. If he doesn't read, let the sadness value be .

MACARON wants to arrange his reading schedule to minimize the sum of sadness value in days. Can you help him find the minimum value?

输入格式

The first line contains three integers and () --- the number of chapters, the days for reading, and the unlucky number.

The second line contains integers () --- the number of characters in each chapter.

输出格式

Output a single integer denoting the minimized sum of the sadness value.

样例

样例输入 1

10 4 5
1 2 3 4 5 5 6 5 4 3

样例输出 1

3

数据范围与提示

Here is an optimal schedule for reading:

  • on the first day, just take a rest, and the sadness value is 0;
  • on the second day, read from chapter 1 to chapter 3, and the sadness value is 0;
  • on the third day, read from chapter 4 to chapter 7, and the sadness value is 2;
  • on the fourth day, read from chapter 8 to chapter 10, and the sadness value is 1.