A1360 | [COCI-2016_2017-contest6]#5 Telefoni
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
There are N desks in a room, placed from left to right, one next to each other. Some desks have phones on them, whereas some desks are empty. All phones are broken, so the phone on the ith desk will ring if the phone at j^th desk rings, which is at most D desks away from the i^th desk. In other words, it holds |j - i| ≤ D. The first and the last desk will always have a phone on them. In the beginning the leftmost phone rings. What is the minimal amount of new phones to be placed on the desks so that the last phone rings?
输入格式
The first line of input contains two positive integers, N (1 ≤ N ≤ 300 000) and D (1 ≤ D ≤ N).
The following line contains N numbers 0 or
1. If the i^th number is 1, then the i^th desk from the left has a phone on it, otherwise the i^th desk is empty.
The following line contains N numbers 0 or
1. If the i^th number is 1, then the i^th desk from the left has a phone on it, otherwise the i^th desk is empty.
输出格式
The first and only line of output must contain the required minimal number of phones.
输入输出样例
输入 #1
4 1 1 0 1 1
输出 #1
1
输入 #2
5 2 1 0 0 0 1
输出 #2
1
输入 #3
8 2 1 1 0 0 1 0 0 1
输出 #3
2
In test cases worth 40 points in total, it will hold 1 ≤ N ≤ 20.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted