結果

問題 No.3587 Too Good to Swap
コンテスト
ユーザー marc2825
提出日時 2026-05-26 13:31:24
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,194 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,108 ms
コンパイル使用メモリ 213,040 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-10 20:53:09
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 46 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

bool fake_wall(const string& X) {
    int n = (int)X.size();
    int i = 0;

    while (i < n && X[i] == 'o') i++;

    int gCount = 0;
    while (i < n && X[i] == 'g') {
        gCount++;
        i++;
    }

    int midO = 0;
    while (i < n && X[i] == 'o') {
        midO++;
        i++;
    }

    int dCount = 0;
    while (i < n && X[i] == 'd') {
        dCount++;
        i++;
    }

    while (i < n && X[i] == 'o') i++;

    return i == n && gCount >= 1 && dCount >= 1 && midO >= 3;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int Q;
    cin >> Q;

    while (Q--) {
        string S, T;
        cin >> S >> T;

        vector<int> cntS(3), cntT(3);
        for (char c : S) {
            if (c == 'd') cntS[0]++;
            else if (c == 'o') cntS[1]++;
            else cntS[2]++;
        }
        for (char c : T) {
            if (c == 'd') cntT[0]++;
            else if (c == 'o') cntT[1]++;
            else cntT[2]++;
        }

        if (cntS != cntT) {
            cout << "No\n";
            continue;
        }

        cout << (fake_wall(S) == fake_wall(T) ? "Yes" : "No") << '\n';
    }
}
0