CF1055A.Metro

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn stations numbered from 11 to nn. Bob lives near the station with number 11, while Alice lives near the station with number ss. The metro line has two tracks. Trains on the first track go from the station 11 to the station nn 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.

今天是爱丽丝的生日,因此她邀请了自己最好的朋友鲍勃来家里做客。现在鲍勃需要找到一种交通方式前往爱丽丝家。

在爱丽丝和鲍勃居住的城市中,第一条地铁线路正在建设中。该地铁线路包含 nn 个车站,编号从 11 到 nn。鲍勃住在编号为 11 的车站附近,而爱丽丝住在编号为 ss 的车站附近。该地铁线路有两条轨道:第一条轨道上的列车从车站 11 开往车站 nn,第二条轨道上的列车则反向行驶(即从车站 nn 开往车站 11)。列车一旦抵达其运行轨道的终点站,便会立即驶入车辆段,因此此后无法再乘坐该列车继续行程。

部分车站尚未开通,还有一些车站仅部分开通——对于每个车站及每条轨道,均已明确该车站在该轨道上是否关闭。若某车站在某条轨道上处于关闭状态,则所有沿该轨道方向行驶的列车均将跳过该站,不作停靠。

当鲍勃获知各车站的开放与关闭情况后,他发现乘坐地铁出行可能出乎意料地复杂。请帮助鲍勃判断:他能否仅依靠地铁抵达爱丽丝家?还是必须另寻其他交通工具?

输入格式

The first line contains two integers nn and ss (2≤s≤n≤10002 \le s \le n \le 1000) — the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 11.

Next lines describe information about closed and open stations.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (ai=0a_i = 0 or ai=1a_i = 1). If ai=1a_i = 1, then the ii-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 nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (bi=0b_i = 0 or bi=1b_i = 1). If bi=1b_i = 1, then the ii-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.

第一行包含两个整数 nn 和 ss(2≤s≤n≤10002 \le s \le n \le 1000),分别表示地铁线路中的车站总数以及爱丽丝家所在的车站编号。鲍勃住在第 11 号车站。

接下来的若干行描述了各车站的开放与关闭状态。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(每个 aia_i 为 00 或 11)。若 ai=1a_i = 1,则第 ii 号车站在第一条轨道(即车站编号递增的方向)上处于开放状态;否则该车站在第一条轨道上关闭。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(每个 bib_i 为 00 或 11)。若 bi=1b_i = 1,则第 ii 号车站在第二条轨道(即车站编号递减的方向)上处于开放状态;否则该车站在第二条轨道上关闭。

输出格式

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).

如果鲍勃能够乘坐地铁到达爱丽丝的家,则输出 "YES"(引号仅用于明确显示),否则输出 "NO"(引号仅用于明确显示)。

您可以以任意大小写(大写或小写)输出每个字母。

输入输出样例

  • 输入#1

    5 3
    1 1 1 1 1
    1 1 1 1 1

    输出#1

    YES
  • 输入#2

    5 4
    1 0 0 0 1
    0 1 1 1 1

    输出#2

    YES
  • 输入#3

    5 2
    0 1 1 1 1
    1 1 1 1 1

    输出#3

    NO

说明/提示

In the first example, all stations are opened, so Bob can simply travel to the station with number 33.

In the second example, Bob should travel to the station 55 first, switch to the second track and travel to the station 44 then.

In the third example, Bob simply can't enter the train going in the direction of Alice's home.

在第一个例子中,所有车站均开放,因此 Bob 可以直接前往编号为 33 的车站。

在第二个例子中,Bob 应首先前往车站 55,然后切换到第二条轨道,再前往车站 44。

在第三个例子中,Bob 根本无法登上驶向 Alice 家方向的列车。

输入解题思路,AI测评打分。不知道怎么写?

首页