結果

問題 No.2629 A replace B replace C
ユーザー nono00
提出日時 2024-02-16 23:32:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 2,673 ms
コンパイル使用メモリ 249,144 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-28 22:25:49
合計ジャッジ時間 4,453 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 54 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

void solve() {
    int n;
    std::cin >> n;
    std::string s, t;
    std::cin >> s >> t;
    std::vector<int> atob, btoc;
    for (int i = 0; i < n; i++) {
        if (s[i] != t[i]) {
            if (s[i] == 'A') {
                atob.push_back(i);
            } else if (s[i] == 'B' && t[i] == 'C') {
                btoc.push_back(i);
            } else {
                std::cout << "No" << '\n';
                return;
            }
        }
    }
    while (!atob.empty() && !btoc.empty()) {
        int lhs = atob.back();
        atob.pop_back();
        int rhs = btoc.back();
        btoc.pop_back();
        s[lhs] = 'B';
        if (t[lhs] == 'C') btoc.push_back(lhs);
        s[rhs] = 'C';
    }
    std::cout << (s == t ? "Yes" : "No") << '\n';
}

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(16);
    int t = 1;

    while (t--) solve();
}
0