A12436 | Tanya and Candies
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Tanya has $n$ candies numbered from $1$ to $n$ . The $i$ -th candy has the weight $a_i$ .
She plans to eat exactly $n-1$ candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day.
Your task is to find the number of such candies $i$ (let's call these candies good) that if dad gets the $i$ -th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days. Note that at first, she will give the candy, after it she will eat the remaining candies one by one.
For example, $n=4$ and weights are $[1, 4, 3, 3]$ . Consider all possible cases to give a candy to dad:
- Tanya gives the $1$ -st candy to dad ( $a_1=1$ ), the remaining candies are $[4, 3, 3]$ . She will eat $a_2=4$ in the first day, $a_3=3$ in the second day, $a_4=3$ in the third day. So in odd days she will eat $4+3=7$ and in even days she will eat $3$ . Since $7 \ne 3$ this case shouldn't be counted to the answer (this candy isn't good).
- Tanya gives the $2$ -nd candy to dad ( $a_2=4$ ), the remaining candies are $[1, 3, 3]$ . She will eat $a_1=1$ in the first day, $a_3=3$ in the second day, $a_4=3$ in the third day. So in odd days she will eat $1+3=4$ and in even days she will eat $3$ . Since $4 \ne 3$ this case shouldn't be counted to the answer (this candy isn't good).
- Tanya gives the $3$ -rd candy to dad ( $a_3=3$ ), the remaining candies are $[1, 4, 3]$ . She will eat $a_1=1$ in the first day, $a_2=4$ in the second day, $a_4=3$ in the third day. So in odd days she will eat $1+3=4$ and in even days she will eat $4$ . Since $4 = 4$ this case should be counted to the answer (this candy is good).
- Tanya gives the $4$ -th candy to dad ( $a_4=3$ ), the remaining candies are $[1, 4, 3]$ . She will eat $a_1=1$ in the first day, $a_2=4$ in the second day, $a_3=3$ in the third day. So in odd days she will eat $1+3=4$ and in even days she will eat $4$ . Since $4 = 4$ this case should be counted to the answer (this candy is good).
In total there $2$ cases which should counted (these candies are good), so the answer is $2$ .
She plans to eat exactly $n-1$ candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day.
Your task is to find the number of such candies $i$ (let's call these candies good) that if dad gets the $i$ -th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days. Note that at first, she will give the candy, after it she will eat the remaining candies one by one.
For example, $n=4$ and weights are $[1, 4, 3, 3]$ . Consider all possible cases to give a candy to dad:
- Tanya gives the $1$ -st candy to dad ( $a_1=1$ ), the remaining candies are $[4, 3, 3]$ . She will eat $a_2=4$ in the first day, $a_3=3$ in the second day, $a_4=3$ in the third day. So in odd days she will eat $4+3=7$ and in even days she will eat $3$ . Since $7 \ne 3$ this case shouldn't be counted to the answer (this candy isn't good).
- Tanya gives the $2$ -nd candy to dad ( $a_2=4$ ), the remaining candies are $[1, 3, 3]$ . She will eat $a_1=1$ in the first day, $a_3=3$ in the second day, $a_4=3$ in the third day. So in odd days she will eat $1+3=4$ and in even days she will eat $3$ . Since $4 \ne 3$ this case shouldn't be counted to the answer (this candy isn't good).
- Tanya gives the $3$ -rd candy to dad ( $a_3=3$ ), the remaining candies are $[1, 4, 3]$ . She will eat $a_1=1$ in the first day, $a_2=4$ in the second day, $a_4=3$ in the third day. So in odd days she will eat $1+3=4$ and in even days she will eat $4$ . Since $4 = 4$ this case should be counted to the answer (this candy is good).
- Tanya gives the $4$ -th candy to dad ( $a_4=3$ ), the remaining candies are $[1, 4, 3]$ . She will eat $a_1=1$ in the first day, $a_2=4$ in the second day, $a_3=3$ in the third day. So in odd days she will eat $1+3=4$ and in even days she will eat $4$ . Since $4 = 4$ this case should be counted to the answer (this candy is good).
In total there $2$ cases which should counted (these candies are good), so the answer is $2$ .
输入格式
The first line of the input contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of candies.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^4$ ), where $a_i$ is the weight of the $i$ -th candy.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^4$ ), where $a_i$ is the weight of the $i$ -th candy.
输出格式
Print one integer — the number of such candies $i$ (good candies) that if dad gets the $i$ -th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days.
输入输出样例
输入 #1
7 5 5 4 5 5 5 6
输出 #1
2
输入 #2
8 4 8 8 7 8 4 4 5
输出 #2
2
输入 #3
9 2 3 4 2 2 3 2 2 4
输出 #3
3
In the first example indices of good candies are $[1, 2]$ .
In the second example indices of good candies are $[2, 3]$ .
In the third example indices of good candies are $[4, 5, 9]$ .
In the second example indices of good candies are $[2, 3]$ .
In the third example indices of good candies are $[4, 5, 9]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted