結果

問題 No.3587 Too Good to Swap
コンテスト
ユーザー marc2825
提出日時 2026-05-30 09:18:15
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 832 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 240 ms
コンパイル使用メモリ 96,108 KB
実行使用メモリ 86,016 KB
最終ジャッジ日時 2026-07-10 20:57:35
合計ジャッジ時間 5,726 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

def is_special(s: str) -> bool:
    last_g = s.rfind('g')
    first_d = s.find('d')

    if last_g == -1 or first_d == -1:
        return False

    return last_g < first_d and first_d - last_g - 1 >= 3

def solve():
    input = sys.stdin.readline

    Q = int(input())
    ans = []

    for _ in range(Q):
        S = input().strip()
        T = input().strip()

        if S.count('d') != T.count('d'):
            ans.append("No")
            continue
        if S.count('o') != T.count('o'):
            ans.append("No")
            continue
        if S.count('g') != T.count('g'):
            ans.append("No")
            continue

        if is_special(S) == is_special(T):
            ans.append("Yes")
        else:
            ans.append("No")

    print("\n".join(ans))

if __name__ == "__main__":
    solve()
0