C - String Transformation Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300300

問題文

英小文字のみからなる文字列 SS, TT が与えられます。

文字列 SS に対して、次の操作を何度でも行うことができます。

操作: 2つの異なる英小文字 c1c_1, c2c_2 を選び、SS に含まれる全ての c1c_1c2c_2 に、c2c_2c1c_1 に置き換える

00 回以上操作を行って、SSTT に一致させられるか判定してください。

制約

  • 1S2×1051 \leq |S| \leq 2 \times 10^5
  • S=T|S| = |T|
  • SS, TT は英小文字のみからなる

入力

入力は以下の形式で標準入力から与えられる。

SS
TT

出力

SSTT に一致させられる場合は Yes、そうでない場合は No を出力せよ。


入力例 1Copy

Copy
azzel
apple

出力例 1Copy

Copy
Yes

次のように操作を行えば、azzelapple にできます。

  • c1c_1 として e を、c2c_2 として l を選ぶと、azzelazzle になる
  • c1c_1 として z を、c2c_2 として p を選ぶと、azzleapple になる

入力例 2Copy

Copy
chokudai
redcoder

出力例 2Copy

Copy
No

どのように操作を行っても chokudairedcoder にできません。


入力例 3Copy

Copy
abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

出力例 3Copy

Copy
Yes

Score : 300300 points

Problem Statement

You are given strings SS and TT consisting of lowercase English letters.

You can perform the following operation on SS any number of times:

Operation: Choose two distinct lowercase English letters c1c_1 and c2c_2, then replace every occurrence of c1c_1 with c2c_2, and every occurrence of c2c_2 with c1c_1.

Determine if SS and TT can be made equal by performing the operation zero or more times.

Constraints

  • 1S2×1051 \leq |S| \leq 2 \times 10^5
  • S=T|S| = |T|
  • SS and TT consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

SS
TT

Output

If SS and TT can be made equal, print Yes; otherwise, print No.


Sample Input 1Copy

Copy
azzel
apple

Sample Output 1Copy

Copy
Yes

azzel can be changed to apple, as follows:

  • Choose e as c1c_1 and l as c2c_2. azzel becomes azzle.
  • Choose z as c1c_1 and p as c2c_2. azzle becomes apple.

Sample Input 2Copy

Copy
chokudai
redcoder

Sample Output 2Copy

Copy
No

No sequences of operation can change chokudai to redcoder.


Sample Input 3Copy

Copy
abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

Sample Output 3Copy

Copy
Yes


2025-03-29 (Sat)
09:17:31 +00:00