問題一覧 > 通常問題

No.2656 XOR Slimes

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 93
作問者 : 👑 hamamu / テスター : 👑 p-adic てんぷら
お気に入りにしたユーザー ProblemId : 10627 / 自分の提出
問題文最終更新日: 2024-02-28 09:03:06
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 419 (順位表) の他の問題:

Problem Statement

There are $N$ slimes on a number line extending left and right.
The $i$-th slime from the left $(i=1,2, \cdots ,N)$ holds an integer $A_i$ and is at position $X_i$.

The slimes can perform the following merge action any number of times, possibly $0$ times.

  1. First, choose $2$ slimes to merge
  2. Let their positions be $X_P,X_Q$ and the integers they hold be $A_P,A_Q$
  3. Next, freely choose a real number $x$
  4. The $2$ slimes move to position $x$ and merge into $1$ slime
  5. The movement incurs a movement cost of $|X_P-x|+|X_Q-x|$
  6. The integer held by the merged slime is the XOR of $A_P$ and $A_Q$

Let $C$ be the total movement cost of all merge actions.
Let $S$ be the sum of the integers held by the slimes remaining at the end.
The slimes acted so that $C+S$ is minimized.
Find the value of $C+S$.

Constraints

  • All inputs are integers
  • $2 \le N \le 5000$
  • $1 \le X_1 \lt X_2 \lt \cdots \lt X_N \le 10^9$
  • $1 \le A_i \lt 2^{30}$

Input

The input is given from standard input in the following format.
$N$
$X_1$ $X_2$ $\cdots$ $X_N$
$A_1$ $A_2$ $\cdots$ $A_N$

Output

Output the value of $C+S$ as an integer, followed by a newline.
It can be proved that the value of $C+S$ is an integer under the constraints of this problem.

Sample

Sample 1
Input
3
2 4 5
2 1 6
Output
8

If the $1$-st and $3$-rd slimes from the left merge at $x=3.5$, the integer held by the merged slime is $2$ XOR $6 = 4$.
The movement cost in this case is $|2-3.5|+|5-3.5|=3$.
If the merge actions end here, the total movement cost is $C=3$ and the sum of the integers is $S=5$, so $C+S=8$.
No sequence of merge actions makes $C+S$ less than $8$, so the answer is $8$.

Sample 2
Input
4
1 4 5 7
1 1 1 1
Output
3
Sample 3
Input
4
10 20 30 40
1 1 1 1
Output
4
Sample 4
Input
3
3 7 15
5 3 6
Output
12

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。