欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1055A.Metro
Metro
Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home.
In the city in which Alice and Bob live, the first metro line is being built. This metro line contains stations numbered from to . Bob lives near the station with number , while Alice lives near the station with number . The metro line has two tracks. Trains on the first track go from the station to the station and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that.
Some stations are not yet open at all and some are only partially open — for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it.
When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport.
Input
The first line contains two integers and () — the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station .
Next lines describe information about closed and open stations.
The second line contains integers ( or ). If , then the -th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track.
The third line contains integers ( or ). If , then the -th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track.
Output
Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise.
You can print each letter in any case (upper or lower).
Note
In the first example, all stations are opened, so Bob can simply travel to the station with number .
In the second example, Bob should travel to the station first, switch to the second track and travel to the station then.
In the third example, Bob simply can't enter the train going in the direction of Alice's home.
Samples
5 3
1 1 1 1 1
1 1 1 1 1
YES
5 4
1 0 0 0 1
0 1 1 1 1
YES
5 2
0 1 1 1 1
1 1 1 1 1
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |