A10810 | Bear and Rectangle Strips
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Limak has a grid that consists of $2$ rows and $n$ columns. The $j$ -th cell in the $i$ -th row contains an integer $t_{i,j}$ which can be positive, negative or zero.
A non-empty rectangle of cells is called nice if and only if the sum of numbers in its cells is equal to $0$ .
Limak wants to choose some nice rectangles and give them to his friends, as gifts. No two chosen rectangles should share a cell. What is the maximum possible number of nice rectangles Limak can choose?
A non-empty rectangle of cells is called nice if and only if the sum of numbers in its cells is equal to $0$ .
Limak wants to choose some nice rectangles and give them to his friends, as gifts. No two chosen rectangles should share a cell. What is the maximum possible number of nice rectangles Limak can choose?
输入格式
The first line of the input contains an integer $n$ ( $1<=n<=300000$ ) — the number of columns in the grid.
The next two lines contain numbers in the grid. The $i$ -th of those two lines contains $n$ integers $t_{i,1},t_{i,2},...,t_{i,n}$ ( $-10^{9}<=t_{i,j}<=10^{9}$ ).
The next two lines contain numbers in the grid. The $i$ -th of those two lines contains $n$ integers $t_{i,1},t_{i,2},...,t_{i,n}$ ( $-10^{9}<=t_{i,j}<=10^{9}$ ).
输出格式
Print one integer, denoting the maximum possible number of cell-disjoint nice rectangles.
输入输出样例
输入 #1
6 70 70 70 70 70 -15 90 -60 -30 30 -30 15
输出 #1
3
输入 #2
4 0 -1 0 0 0 0 1 0
输出 #2
6
输入 #3
3 1000000000 999999999 -1000000000 999999999 -1000000000 -999999998
输出 #3
1
In the first sample, there are four nice rectangles:
Limak can't choose all of them because they are not disjoint. He should take three nice rectangles: those denoted as blue frames on the drawings.
In the second sample, it's optimal to choose six nice rectangles, each consisting of one cell with a number $0$ .
In the third sample, the only nice rectangle is the whole grid — the sum of all numbers is $0$ . Clearly, Limak can choose at most one nice rectangle, so the answer is $1$ .
Limak can't choose all of them because they are not disjoint. He should take three nice rectangles: those denoted as blue frames on the drawings.
In the second sample, it's optimal to choose six nice rectangles, each consisting of one cell with a number $0$ .
In the third sample, the only nice rectangle is the whole grid — the sum of all numbers is $0$ . Clearly, Limak can choose at most one nice rectangle, so the answer is $1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted