Codeforces-Round 394#B-Dasha and friends
2017-02-01 10:40
369 查看
B. Dasha and friends
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length L, in distinct points of which there are n barriers.
Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track.
Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the n barriers.
Thus, each of them wrote n integers in the ascending order, each of them was between 0 and L - 1,
inclusively.
Consider
an example. Let L = 8, blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down
the sequence [2, 4, 6], and Sasha writes down [1, 5, 7].
There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they
participated on different tracks.
Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from
above.
Input
The first line contains two integers n and L (1 ≤ n ≤ 50, n ≤ L ≤ 100)
— the number of barriers on a track and its length.
The second line contains n distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of
its appearance. All integers are in the range from 0 to L - 1 inclusively.
The second line contains n distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order
of its overcoming. All integers are in the range from 0 to L - 1 inclusively.
Output
Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from
the same points on the track). Otherwise print "NO" (without quotes).
Examples
input
4000
output
input
output
input
output
Note
The first test is analyzed in the statement.
题解见:http://blog.lightina.cn/2017/02/01/Codeforces-Round-394-B-Dasha-and-friends/
不收录我也很绝望啊= =
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length L, in distinct points of which there are n barriers.
Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track.
Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the n barriers.
Thus, each of them wrote n integers in the ascending order, each of them was between 0 and L - 1,
inclusively.
Consider
an example. Let L = 8, blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down
the sequence [2, 4, 6], and Sasha writes down [1, 5, 7].
There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they
participated on different tracks.
Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from
above.
Input
The first line contains two integers n and L (1 ≤ n ≤ 50, n ≤ L ≤ 100)
— the number of barriers on a track and its length.
The second line contains n distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of
its appearance. All integers are in the range from 0 to L - 1 inclusively.
The second line contains n distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order
of its overcoming. All integers are in the range from 0 to L - 1 inclusively.
Output
Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from
the same points on the track). Otherwise print "NO" (without quotes).
Examples
input
4000
3 8 2 4 6 1 5 7
output
YES
input
4 9 2 3 5 8 0 1 3 6
output
YES
input
2 4 1 3 1 2
output
NO
Note
The first test is analyzed in the statement.
题解见:http://blog.lightina.cn/2017/02/01/Codeforces-Round-394-B-Dasha-and-friends/
不收录我也很绝望啊= =
相关文章推荐
- Codeforces-Round 394#A-Dasha and Stairs
- Codeforces-Round 394#C-Dasha and Password'
- Codeforces Round #394(Div. 2)B. Dasha and friends【思维+暴力】
- Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力
- Codeforces Round #394 (Div. 2) B. Dasha and friends
- 【codeforces 761B】Dasha and friends
- Codeforces 761B-Dasha and friends
- 【codeforces 515B】Drazil and His Happy Friends
- CodeForces 295 C.Greg and Friends(bfs+dp)
- [边双连通分量 缩点 虚树 欧拉序列LCA] Codeforces 639F VK Cup 2016 - Round 1 F. Bear and Chemistry
- 【CODEFORCES】 B. Friends and Presents
- Codeforces 689D -Friends and Subsequences (RMQ查询-> ST表+二分)
- Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组
- Codeforces Round #394 (Div. 2)(A. Dasha and Stairs,B. Dasha and friends,C. Dasha and Password)
- Codeforces 761C-Dasha and Password
- Codeforces Round 761F - Dasha and Photos
- Codeforces - AIM Tech Round (Div. 2)C - Graph and String
- Codeforces 754E:Dasha and cyclic table
- Codeforces 453 B Little Pony and Harmony Chest(Round 259 div.1 B/div.2 D)
- CodeForces 66D - Petya and His Friends(构造)