Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 400 点
問題文
N 個の一列に並んだマス目があり、左から順に番号 1, 2, ..., N がついています。長さ N の .
, #
からなる文字列 S が与えられ、S の i 文字目が #
のときマス目 i には岩が置かれており、S の i 文字目が .
のときマス目 i には何も置かれていません。
最初、マス目 A にすぬけ君、B にふぬけ君がいます。
あなたは以下の操作を好きなだけ繰り返すことができます。
- すぬけ君かふぬけ君を選び、1 マス右か 2 マス右にジャンプさせる。このときジャンプ先にマスが存在しなければならず、またそのマスに岩が置かれていたりもう一人がいてはならない。
あなたはこの操作を繰り返し、マス目 C にすぬけ君が、D にふぬけ君がいるようにしたいです。
このようなことが可能かどうかを判定してください。
制約
- 4 \leq N \leq 200,000
- S は
.
,#
からなる長さ N の文字列 - 1 \leq A, B, C, D \leq N
- マス目 A, B, C, D に岩は置かれていない
- A, B, C, D はすべて異なる
- A < B
- A < C
- B < D
入力
入力は以下の形式で標準入力から与えられる。
N A B C D S
出力
題意が達成可能ならば Yes
、不可能ならば No
を出力せよ。
入力例 1
7 1 3 6 7 .#..#..
出力例 1
Yes
たとえば、以下のように移動させれば良いです(すぬけ君、ふぬけ君を A
, B
で表します)
A#B.#.. A#.B#.. .#AB#.. .#A.#B. .#.A#B. .#.A#.B .#..#AB
入力例 2
7 1 3 7 6 .#..#..
出力例 2
No
入力例 3
15 1 3 15 13 ...#.#...#.#...
出力例 3
Yes
Score : 400 points
Problem Statement
There are N squares arranged in a row, numbered 1, 2, ..., N from left to right.
You are given a string S of length N consisting of .
and #
. If the i-th character of S is #
, Square i contains a rock; if the i-th character of S is .
, Square i is empty.
In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.
You can repeat the following operation any number of times:
- Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.
You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.
Determine whether this is possible.
Constraints
- 4 \leq N \leq 200\ 000
- S is a string of length N consisting of
.
and#
. - 1 \leq A, B, C, D \leq N
- Square A, B, C and D do not contain a rock.
- A, B, C and D are all different.
- A < B
- A < C
- B < D
Input
Input is given from Standard Input in the following format:
N A B C D S
Output
Print Yes
if the objective is achievable, and No
if it is not.
Sample Input 1
7 1 3 6 7 .#..#..
Sample Output 1
Yes
The objective is achievable by, for example, moving the two persons as follows. (A
and B
represent Snuke and Fnuke, respectively.)
A#B.#.. A#.B#.. .#AB#.. .#A.#B. .#.A#B. .#.A#.B .#..#AB
Sample Input 2
7 1 3 7 6 .#..#..
Sample Output 2
No
Sample Input 3
15 1 3 15 13 ...#.#...#.#...
Sample Output 3
Yes