結果

問題 No.3798 algo to goal
コンテスト
ユーザー marc2825
提出日時 2026-11-08 01:23:56
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 258 ms / 2,000 ms
+ 748µs
コード長 1,102 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,599 ms
コンパイル使用メモリ 220,540 KB
実行使用メモリ 7,200 KB
最終ジャッジ日時 2026-11-13 22:01:07
合計ジャッジ時間 11,733 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main() {
    const int C = 26;

    int Q;
    cin >> Q;

    while (Q--) {
        string S, T;
        cin >> S >> T;
        int N = S.size();

        vector<vector<int>> A(2, vector<int>(C, 0));
        vector<vector<int>> B(2, vector<int>(C, 0));
        for (int i = 0; i < N; i++) {
            A[i % 2][S[i] - 'a']++;
            B[i % 2][T[i] - 'a']++;
        }

        if (A != B) {
            cout << "No\n";
            continue;
        }

        bool dup = false;
        for (int p = 0; p < 2; p++) {
            for (int c = 0; c < C; c++) {
                if (A[p][c] >= 2) dup = true;
            }
        }

        if (dup) {
            cout << "Yes\n";
            continue;
        }

        int x = 0, y = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i % 2 != j % 2) continue;
                if (S[i] > S[j]) x++;
                if (T[i] > T[j]) y++;
            }
        }

        cout << (x % 2 == y % 2 ? "Yes" : "No") << '\n';
    }

    return 0;
}
0