結果
| 問題 | No.3798 algo to goal |
| ユーザー |
|
| 提出日時 | 2026-11-13 23:07:56 |
| 言語 | PyPy3 (8.0.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 652 ms / 2,000 ms |
| + 451µs | |
| コード長 | 1,315 bytes |
| 記録 | |
| コンパイル時間 | 102 ms |
| コンパイル使用メモリ | 64,116 KB |
| 実行使用メモリ | 81,276 KB |
| 最終ジャッジ日時 | 2026-11-13 23:08:17 |
| 合計ジャッジ時間 | 20,493 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 40 |
ソースコード
from collections import Counter
def reduce(S):
N = len(S)
seen = {S}
stack = [S]
while stack:
s = stack.pop()
for i in range(N - 3):
t = s[:i] + s[i+2:i+4] + s[i:i+2] + s[i+4:]
if t in seen:
continue
seen.add(t)
stack.append(t)
return min(seen)
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)
if N < 6:
if reduce(S) == reduce(T):
print("Yes")
else:
print("No")
continue
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")