問題一覧 > 通常問題

No.3109 Swap members

レベル : / AI推定難易度 : 550 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 199
作問者 : Naru820 / テスター : kenken714 ponjuice
お気に入りにしたユーザー ProblemId : 12193 / 自分の提出
問題文最終更新日: 2025-04-17 10:53:35
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
CPCTF 2025 : PPC (順位表) の他の問題:

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.

ActionOrder 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もしくは右上の雲マークをクリックしてアカウントを作成してください。