A11839 | Chess Placing
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a chessboard of size $1×n$ . It is guaranteed that $n$ is even. The chessboard is painted like this: "BWBW $...$ BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .
In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.
Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .
In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.
Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).
输入格式
The first line of the input contains one integer $n$ ( $2<=n<=100$ , $n$ is even) — the size of the chessboard.
The second line of the input contains  integer numbers  ( $1<=p_{i}<=n$ ) — initial positions of the pieces. It is guaranteed that all the positions are distinct.
The second line of the input contains  integer numbers  ( $1<=p_{i}<=n$ ) — initial positions of the pieces. It is guaranteed that all the positions are distinct.
输出格式
Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.
输入输出样例
输入 #1
6 1 2 6
输出 #1
2
输入 #2
10 1 2 3 4 5
输出 #2
10
In the first example the only possible strategy is to move the piece at the position $6$ to the position $5$ and move the piece at the position $2$ to the position $3$ . Notice that if you decide to place the pieces in the white cells the minimum number of moves will be $3$ .
In the second example the possible strategy is to move  in 4 moves, then  in 3 moves,  in 2 moves and  in 1 move.
In the second example the possible strategy is to move  in 4 moves, then  in 3 moves,  in 2 moves and  in 1 move.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted