結果

問題 No.3798 algo to goal
ユーザー GOTKAKO
提出日時 2026-11-13 22:55:14
言語 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  
実行時間 60 ms / 2,000 ms
+ 558µs
コード長 2,438 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,572 ms
コンパイル使用メモリ 223,392 KB
実行使用メモリ 9,528 KB
最終ジャッジ日時 2026-11-13 22:55:21
合計ジャッジ時間 6,746 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

    int test; cin >> test;
    while(test--){
        string s,t; cin >> s >> t;
        string s1 = "",s2 = "",t1 = "",t2 = "";
        int N = s.size();


        for(int i=0; i<N; i++){
            if(i%2) s2 += s.at(i),t2 += t.at(i);
            else s1 += s.at(i),t1 += t.at(i);
        }

        bool yes = true;
        int check = 3;
        {
            auto one = s1,two = t1;
            sort(one.begin(),one.end());
            sort(two.begin(),two.end());
            if(one == two){
                vector<int> P(26,-1);
                int same = 0;
                for(int i=0; i<t1.size(); i++){
                    int pos = t1.at(i)-'a';
                    if(P.at(pos) == -1) P.at(pos) = i;
                    else same = 3;
                }
                if(same != 3){
                    int now = 0;
                    for(int i=0; i<s1.size(); i++){
                        int p = P.at(s1.at(i)-'a');
                        for(int k=0; k<i; k++){
                            int q = P.at(s1.at(k)-'a');
                            if(q > p) now++; 
                        }
                    }
                    now %= 2;
                    check &= 1<<now;
                }
            }
            else yes = false;
        }
        {
            auto one = s2,two = t2;
            sort(one.begin(),one.end());
            sort(two.begin(),two.end());
            if(one == two){
                vector<int> P(26,-1);
                int same = 0;
                for(int i=0; i<t2.size(); i++){
                    int pos = t2.at(i)-'a';
                    if(P.at(pos) == -1) P.at(pos) = i;
                    else same = 3;
                }
                if(same != 3){
                    int now = 0;
                    for(int i=0; i<s2.size(); i++){
                        int p = P.at(s2.at(i)-'a');
                        for(int k=0; k<i; k++){
                            int q = P.at(s2.at(k)-'a');
                            if(q > p) now++; 
                        }
                    }
                    now %= 2;
                    check &= 1<<now;
                }
            }
            else yes = false;
        }
        if(check == 0) yes = false; 
        

        if(yes) cout << "Yes\n";
        else cout << "No\n";
    }
}
0