結果

問題 No.3798 algo to goal
ユーザー iastm
提出日時 2026-11-13 23:34:54
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 737 ms / 2,000 ms
+ 666µs
コード長 871 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 87 ms
コンパイル使用メモリ 64,512 KB
実行使用メモリ 81,528 KB
最終ジャッジ日時 2026-11-13 23:35:16
合計ジャッジ時間 21,152 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import Counter

def inv(a, b):
    pos = [-1] * 26
    for i in range(len(b)):
        pos[b[i]] = i
    result = 0
    count = [0] * 26
    for c in a:
        c = pos[c]
        result += sum(count[c+1:])
        count[c] += 1
    return result

for _ in range(int(input())):
    S = input()
    T = input()
    N = len(S)
    s0 = [ord(c) - ord('a') for c in S[0:N:2]]
    s1 = [ord(c) - ord('a') for c in S[1:N:2]]
    t0 = [ord(c) - ord('a') for c in T[0:N:2]]
    t1 = [ord(c) - ord('a') for c in T[1:N:2]]
    cs0 = Counter(s0)
    cs1 = Counter(s1)
    if cs0 != Counter(t0) or cs1 != Counter(t1):
        print("No")
        continue
    if any(v > 1 for v in cs0.values()) or any(v > 1 for v in cs1.values()):
        print("Yes")
        continue
    if (inv(s0, t0) + inv(s1, t1)) % 2 == 0:
        print("Yes")
    else:
        print("No")
0