A12999 | Send Boxes to Alice (Easy Version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is the easier version of the problem. In this version, $1 \le n \le 10^5$ and $0 \le a_i \le 1$ . You can hack this problem only if you solve and lock both problems.
Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepare $n$ boxes of chocolate, numbered from $1$ to $n$ . Initially, the $i$ -th box contains $a_i$ chocolate pieces.
Since Bob is a typical nice guy, he will not send Alice $n$ empty boxes. In other words, at least one of $a_1, a_2, \ldots, a_n$ is positive. Since Alice dislikes coprime sets, she will be happy only if there exists some integer $k > 1$ such that the number of pieces in each box is divisible by $k$ . Note that Alice won't mind if there exists some empty boxes.
Charlie, Alice's boyfriend, also is Bob's second best friend, so he decides to help Bob by rearranging the chocolate pieces. In one second, Charlie can pick up a piece in box $i$ and put it into either box $i-1$ or box $i+1$ (if such boxes exist). Of course, he wants to help his friend as quickly as possible. Therefore, he asks you to calculate the minimum number of seconds he would need to make Alice happy.
Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepare $n$ boxes of chocolate, numbered from $1$ to $n$ . Initially, the $i$ -th box contains $a_i$ chocolate pieces.
Since Bob is a typical nice guy, he will not send Alice $n$ empty boxes. In other words, at least one of $a_1, a_2, \ldots, a_n$ is positive. Since Alice dislikes coprime sets, she will be happy only if there exists some integer $k > 1$ such that the number of pieces in each box is divisible by $k$ . Note that Alice won't mind if there exists some empty boxes.
Charlie, Alice's boyfriend, also is Bob's second best friend, so he decides to help Bob by rearranging the chocolate pieces. In one second, Charlie can pick up a piece in box $i$ and put it into either box $i-1$ or box $i+1$ (if such boxes exist). Of course, he wants to help his friend as quickly as possible. Therefore, he asks you to calculate the minimum number of seconds he would need to make Alice happy.
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 10^5$ ) — the number of chocolate boxes.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 1$ ) — the number of chocolate pieces in the $i$ -th box.
It is guaranteed that at least one of $a_1, a_2, \ldots, a_n$ is positive.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 1$ ) — the number of chocolate pieces in the $i$ -th box.
It is guaranteed that at least one of $a_1, a_2, \ldots, a_n$ is positive.
输出格式
If there is no way for Charlie to make Alice happy, print $-1$ .
Otherwise, print a single integer $x$ — the minimum number of seconds for Charlie to help Bob make Alice happy.
Otherwise, print a single integer $x$ — the minimum number of seconds for Charlie to help Bob make Alice happy.
输入输出样例
输入 #1
3 1 0 1
输出 #1
2
输入 #2
1 1
输出 #2
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted