結果

問題 No.3798 algo to goal
ユーザー marc2825
提出日時 2026-11-08 02:24:19
言語 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
結果
WA  
実行時間 -
コード長 1,465 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,464 ms
コンパイル使用メモリ 224,664 KB
実行使用メモリ 9,928 KB
最終ジャッジ日時 2026-11-13 22:03:52
合計ジャッジ時間 46,547 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 17 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

    int Q;
    cin >> Q;

    const int C = 26;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

    using Clock = chrono::steady_clock;
    auto deadline = Clock::now() + chrono::milliseconds(1800);

    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;
        }

        if (N > 52 || S == T) {
            cout << "Yes\n";
            continue;
        }

        auto now = Clock::now();
        auto limit = now + (deadline - now) / (Q + 1);

        uniform_int_distribution<int> dist(0, N - 4);

        string s = S;
        bool ok = false;
        int steps = 0;

        while (Clock::now() < limit) {
            int i = dist(rng);

            swap(s[i], s[i + 2]);
            swap(s[i + 1], s[i + 3]);

            if (s == T) {
                ok = true;
                break;
            }

            steps++;
            if (steps % (N * 10) == 0) {
                s = S;
            }
        }

        cout << (ok ? "Yes" : "No") << '\n';
    }

    return 0;
}
0