結果

問題 No.2629 A replace B replace C
ユーザー lloyz
提出日時 2024-02-29 20:34:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 67,868 KB
最終ジャッジ日時 2024-09-29 12:57:36
合計ジャッジ時間 4,980 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()
t = input()
cnt = 0
is_AC = False
flag = False
for i in range(n):
    if s[i] == 'A' and t[i] == 'B':
        cnt += 1
        if cnt == 0:
            flag = True
    elif s[i] == 'B' and t[i] == 'C':
        cnt -= 1
        if cnt == 0:
            flag = True
    elif s[i] == 'A' and t[i] == 'C':
        is_AC = True
    elif s[i] == t[i]:
        pass
    else:
        print("No")
        exit()
if cnt != 0:
    print("No")
else:
    if is_AC:
        if flag:
            print("Yes")
        else:
            print("No")
    else:
        print("Yes")
0