結果

問題 No.3587 Too Good to Swap
コンテスト
ユーザー iastm
提出日時 2026-07-11 01:03:08
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 299 ms / 2,000 ms
+ 598µs
コード長 541 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 933 ms
コンパイル使用メモリ 96,108 KB
実行使用メモリ 108,248 KB
最終ジャッジ日時 2026-07-11 01:03:17
合計ジャッジ時間 6,889 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

for _ in range(int(input())):
    S = input()
    T = input()
    N = len(S)
    sg = [i for i in range(N) if S[i] == 'g']
    sd = [i for i in range(N) if S[i] == 'd']
    tg = [i for i in range(N) if T[i] == 'g']
    td = [i for i in range(N) if T[i] == 'd']
    if len(sg) != len(tg) or len(sd) != len(td):
        print("No")
        continue
    is_free_s = not sg or not sd or sd[0] - sg[-1] <= 2
    is_free_t = not tg or not td or td[0] - tg[-1] <= 2
    if is_free_s == is_free_t:
        print("Yes")
    else:
        print("No")
0