結果

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

ソースコード

diff #
raw source code

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    auto f = [&](string s){
        array<int, 26> cnt0{}, cnt1{};
        ll s0 = 0, s1 = 0;
        for(int i = 0; i < (int)s.size(); i++){
            int c = s[i] - 'a';
            if(i % 2 == 0){
                for(int j = c + 1; j < 26; j++) s0 += cnt0[j];
                cnt0[c]++;
            }else{
                for(int j = c + 1; j < 26; j++) s1 += cnt1[j];
                cnt1[c]++;
            }
        }
        s0 &= 1, s1 &= 1;
        for(int i = 0; i < 26; i++){
            if(cnt0[i] >= 2) s0 |= 3;
        }
        for(int i = 0; i < 26; i++){
            if(cnt1[i] >= 2) s1 |= 3;
        }
        return make_tuple(cnt0, cnt1, s0, s1);
    };
    while(q--){
        string s, t;
        cin >> s >> t;
        if(s == t){
            cout << "Yes\n";
            continue;
        }
        auto [sC0, sC1, sS0, sS1] = f(s);
        auto [tC0, tC1, tS0, tS1] = f(t);
        if(sS0 == 3 || sS1 == 3){
            cout << (sC0 == tC0 && sC1 == tC1 ? "Yes" : "No") << '\n';
        }else{
            cout << (sC0 == tC0 && sC1 == tC1 && ((sS0 ^ tS0) == (sS1 ^ tS1)) ? "Yes" : "No") << '\n';
        }
    }
}
0