No.3109 Swap members
Problem Statement
$N$ members of traP are standing in a horizontal row in the club room. The username of the $i$-th member from the left ($1 \leq i \leq N$) is $S_i$.
In preparation for CPCTF, you want to rearrange them so that the username of the $i$-th member from the left ($1 \leq i \leq N$) is $T_i$.
However, because the club room is narrow, you can only perform the following action.
- Choose an integer $i$ between $1$ and $N - K$, inclusive, and swap the positions of the $i$-th member from the left and the $i + K$-th member.
Determine whether the members can be brought into the target arrangement by repeating this action any number of times.
Constraints
- $1 \leq K < N \leq 10^5$
- $N, K$ are integers
- $S_i, T_i$ are strings of length between $1$ and $32$, inclusive, consisting of uppercase and lowercase English letters
- $i \neq j \Rightarrow S_i \neq S_j$
- $T$ is a permutation of $S$
Input
$N\ K$ $S_1$ $S_2$ $\vdots$ $S_N$ $T_1$ $T_2$ $\vdots$ $T_N$
Output
Print Yes on one line if the members can be brought into the target arrangement, and No if they cannot, followed by a newline.
Sample
Sample 1
Input
5 2 Alice Bob Charlie David Eve Eve David Alice Bob Charlie
Output
Yes
The members can be brought into the target arrangement by performing the action $3$ times as follows.
| Action | Order of members |
|---|---|
| (Initial state) | Alice, Bob, Charlie, David, Eve |
| $i = 3$ | Alice, Bob, Eve, David, Charlie |
| $i = 2$ | Alice, David, Eve, Bob, Charlie |
| $i = 1$ | Eve, David, Alice, Bob, Charlie |
Sample 2
Input
4 3 TechChan Picody OokayamaSakura trapyojo trapyojo OokayamaSakura Picody TechChan
Output
No
No matter how you perform the actions, the members cannot be brought into the target arrangement.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。